To je zajímavé, na Linuxu to v kódu je - ten řádek 22 s checkcast: static void process(java.util.List); Code: 0: aload_0 1: invokeinterface #2, 1; //InterfaceMethod java/util/List.iterator:()Ljava/util/Iterator; 6: astore_1 7: aload_1 8: invokeinterface #3, 1; //InterfaceMethod java/util/Iterator.hasNext:()Z 13: ifeq 34 16: aload_1 17: invokeinterface #4, 1; //InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object; 22: checkcast #5; //class cz/makub/TypovaZahada$Employee 25: astore_2 26: aload_2 27: checkcast #6; //class java/util/Map 30: astore_3 31: goto 7 34: return
Takže to není vlastnost JVM, ale překladače.
Makub
Zdeněk Troníček napsal(a):
> V byte kodu pretypovani neni. Metoda
>
> protected static void process(List<Employee> list) {
> for (Object o : list) {
> System.out.println(o);
> }
> }
>
> se prelozi takto:
>
> protected static void process(java.util.List);
> Code:
> 0: aload_0
> 1: invokeinterface #2, 1; //InterfaceMethod
> java/util/List.iterator:()Ljava/util/Iterator;
> 6: astore_1
> 7: aload_1
> 8: invokeinterface #3, 1; //InterfaceMethod
> java/util/Iterator.hasNext:()Z
> 13: ifeq 33
> 16: aload_1
> 17: invokeinterface #4, 1; //InterfaceMethod
> java/util/Iterator.next:()Ljava/lang/Object;
> 22: astore_2
> 23: getstatic #5; //Field
> java/lang/System.out:Ljava/io/PrintStream;
> 26: aload_2
> 27: invokevirtual #6; //Method
> java/io/PrintStream.println:(Ljava/lang/Object;)V
> 30: goto 7
> 33: return
--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Supercomputing Center Brno Martin Kuba
Institute of Computer Science email: [email protected]
Masaryk University http://www.ics.muni.cz/~makub/
Botanicka 68a, 60200 Brno, CZ mobil: +420-603-533775
--------------------------------------------------------------
smime.p7s
Description: S/MIME Cryptographic Signature
