1

What does it create instead of a String class? Unless java 'Isn't playing by its own rules' could I program my own Standard Library that utilizes string literals differently? Could I change what the string literal actually does even with the Java Standard Library being used?

It just seems strange to have something embedded in the language that has so much to do with a very specific class in the API that's not even primitive.

briefchase
  • 11
  • 2
  • You could provide an alternative implementation of `java.lang.String`. But that's it. – Andy Turner Sep 06 '18 at 13:55
  • String is sequence of characters togather. Java provides the implementation of String in `String.java` and adds needed features and behaviour for easy and efficient use. If you do not want to use it then You can use `char[] arr = new char[N]`, where `N` is number of characters or you can create it like `char[] arr = {'a','l','p','h','a'};` and then use. – nits.kk Sep 06 '18 at 13:57
  • String literals go into the constant pool of a .class file as UTF-8 strings, typed as java.lang.String. Then in memory as String they in general use an array of UTF-16 chars. So that is that. Maybe your own scripting language: using the **Java Scripting API**. – Joop Eggen Sep 06 '18 at 13:57
  • 2
    If you think that `String` is somehow a special class, it is: [it's called out specially in the language spec](https://docs.oracle.com/javase/specs/jls/se9/html/jls-4.html#jls-4.3.3). – Andy Turner Sep 06 '18 at 13:59
  • Related: [Why is there no primitive type for String?](https://stackoverflow.com/questions/2099257/why-is-there-no-primitive-type-for-string) – Thomas Francois Sep 06 '18 at 13:59

0 Answers0