How java create objects implicitly? Like in case of String class

前端 未结 3 1497
悲哀的现实
悲哀的现实 2021-01-19 19:06

I can\'t understand how an object is created implicitly.

Example:

String s = \"implicit instantiation\";

Can I make my own class w

3条回答
  •  攒了一身酷
    2021-01-19 19:41

    No, String instantiation is handled implicitly by the compiler. Only the String and Array classes have this property.

    String greeting = "Hello world!";
    char[] helloArray = { 'h', 'e', 'l', 'l', 'o', '.' };
    

    Autoboxing allows you to implicitly instantiate objects of primitive wrapper types, but that's also a special case handled by the compiler. You can't create your own classes with this ability.

    Boolean b = false;
    Integer i = 0;
    Double pi = 3.1416;
    

提交回复
热议问题