2012-01-06 14 views

Odpowiedz

7

.class kluczowe dostać przedmiot Class reprezentować zarówno prymitywne rodzaje i typy klas, natomiast pole do wrapper primitive class.typ pozwala uzyskać Class prymitywnego typu, która otacza obiekt.

+0

Czy nie jest to '.class' prostu cukier syntaktyczny? –

16

Absolutnie nic. Jeśli uruchomisz poniższy kod, zobaczysz, że int.class to to samo, co Integer.TYPE.

public class Test { 
    public static void main(final String[] args) { 
     System.out.println(int.class == Integer.TYPE); 
    } 
} 
1

absolutnie fałszywy czek to:

public static void main(String[] args) { 
      System.out.println(int.class.equals(Integer.TYPE)); 
      System.out.println(Integer.class.equals(Integer.TYPE)); 
     } 

wyjściowa: prawda fałszywe

Boolean.TYPE == boolean.class 
Byte.TYPE == byte.class 
Short.TYPE == short.class 
Character.TYPE == char.class 
Integer.TYPE == int.class 
Long.TYPE == long.class 
Float.TYPE == float.class 
Double.TYPE == double.class 
Void.TYPE == void.class 
+0

To jest poprawne wyjście. Ponieważ 'Integer' faktycznie * nie * zawija' Integer'. – skiwi

Powiązane problemy