Generics help

What will happen if i compile the foll code:

import java.util.*;

publicclass Gen

{

publicstaticvoid main(Strring [] ar)

{

Collection<Integer> arr=new ArrayList<Integer>();

ArrayList<Integer> arr1=new ArrayList<Integer>();

//[i] some elements are added [/i]

if(arrinstanceof Collection<Integer>)System.out.println("is an instance");

}

}

[926 byte] By [sjosh_theonea] at [2007-11-27 11:38:50]
# 1

The only person who can tell what will happen if you compile something is in fact you. So I suggest you compile that and see what happens.

cotton.ma at 2007-7-29 17:22:33 > top of Java-index,Java Essentials,Training...
# 2

yeah am just asking u people.

i know most of the will go wrong. (^ _ ~)

sjosh_theonea at 2007-7-29 17:22:33 > top of Java-index,Java Essentials,Training...
# 3

OK fine. can anyone tell me why we get a compile time error on the following line:

if(arr instanceof Collection<Integer>)

null

sjosh_theonea at 2007-7-29 17:22:33 > top of Java-index,Java Essentials,Training...
# 4

> OK fine. can anyone tell me why we get a compile time

> error on the following line:

It wont throw error !!!!

> if(arr instanceof Collection<Integer>)

>

>

>

> null

Well it wont throw error mate ?

New_Kida at 2007-7-29 17:22:33 > top of Java-index,Java Essentials,Training...
# 5

> What will happen if i compile the foll code:

> > import java.util.*;

> public class Gen

> {

> public static void main(Strring [] ar)

> {

> Collection<Integer> arr=new ArrayList<Integer>();

> ArrayList<Integer> arr1=new ArrayList<Integer>();

> /[i] some elements are added [/i]

> if(arr instanceof

> Collection<Integer>)System.out.println("is an

> instance");

>

>

> }

> }

>

The only error I see is

public static void main([b]Strring[/b] [] ar)

New_Kida at 2007-7-29 17:22:33 > top of Java-index,Java Essentials,Training...
# 6

ok . that is not Strring . its String .

was in a hurry.

btw i got a compile time error with the same line but dont know why.

sjosh_theonea at 2007-7-29 17:22:33 > top of Java-index,Java Essentials,Training...
# 7

what does the error say? anything more than "i refuse to compile this line"?

OnBringera at 2007-7-29 17:22:33 > top of Java-index,Java Essentials,Training...
# 8

it says:

illegal generic type for instanceof

sjosh_theonea at 2007-7-29 17:22:33 > top of Java-index,Java Essentials,Training...
# 9

Generic type information is not available at runtime (when you're using the instanceof operator). Make itif (arr instanceof Collection) ...

dwga at 2007-7-29 17:22:33 > top of Java-index,Java Essentials,Training...