What is the difference between data types and literals in Java?

前端 未结 10 1687
旧时难觅i
旧时难觅i 2021-01-30 08:59

What is the difference between data types and literals in Java?

10条回答
  •  盖世英雄少女心
    2021-01-30 09:43

     String string = "Hello World";
     <  1 > <  2 >   <     3     >
    

    1 is a data type, 2 a variable name, 3 a (String) literal

    From the JLS:

    A literal is the source code representation of a value of a primitive type [like 1, true, 't'or 1.2f], the String type [like "" or Something], or the null type [null]

提交回复
热议问题