Hello,
This probably seems simple, well I'm sure all of mine seem simple, so here it goes. I am having trouble constructing strings. str1, str3, and str4 give pre-compile errors and show up yellow in my IDE. The pre-compile errors are commented in the code below. str2 gives a pre-compile error (commented in code below) and also a runtime error. The runtime error was:
Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - Erroneous tree type: <any>
at hsstringdemo.HSStringDemo.main(HSStringDemo.java:1 4)
Line 14 is where the string is declared and initialized, which I think is also called the string constructor.
I imported java.lang.Object and java.lang.String in hopes that something was not defined, but to no avail. I tried using the code tags this time, seems simple, but tell me how I am doing.
package hsstringdemo; import java.lang.Object; import java.lang.String; public class HSStringDemo { public static void main(String[] args) { // Declare strings in various ways. String str1 = new String("Java strings are objects."); //Pre-Compile Error: String constructor invocation String str2 = new "They are constructed in various ways."; //Pre-Compile Error: <identifier> expected String str3 = new String(str1); //Pre-Compile Error: String constructor invocation String str4 = new String(str1 + str3); //Pre-Compile Error: String constructor invocation System.out.println(str1); System.out.println(str2); System.out.println(str3); System.out.println(str4); } }