|
Re: Java/Eclipse thinks that an ArrayList is some random Object [message #968744 is a reply to message #968604] |
Fri, 02 November 2012 18:11 |
Eclipse User |
|
|
|
Hi,
You are getting runtime and compile time mixed up. At compile time the
compiler has no concept of the contents. All it knows it that the
contents are some kind of Object. Since you are not using generics the
contents could be a String, Integer, ArrayList, HashMap. It has no idea.
The compiler is the one that determines what constructor to use. It
needs to put the call to that constructor in the compiled .class. Since
it doesn't know it assumes worst case, that it is an Object, and so it
can't find any such constructor.
By the way this is not eclipse jdt question. This is a basic java
question and so this should be asked on a basic java forum.
Rich
|
|
|
Re: Java/Eclipse thinks that an ArrayList is some random Object [message #968930 is a reply to message #968604] |
Fri, 02 November 2012 21:37 |
Eclipse User |
|
|
|
fwiw you are not showing us z0. its probably Arraylist<ArrayList> type.
On 11/2/2012 11:42 AM, A U wrote:
> 1 System.out.println(z0.get(0)); //prints; [[OverallHeightAsString, OverallWidthAsString, OverallHeight]]
> 2 System.out.println(z0.get(0).getClass()); //prints; class java.util.ArrayList
> 3
> 4 ArrayList arrayList1 = new ArrayList(z0.get(0)); 5 System.out.println(arrayList1.get(0)); //prints; [OverallHeightAsString, OverallWidthAsString, OverallHeight]
> 6 System.out.println(arrayList1.get(0).getClass()); //prints; class java.util.ArrayList
> 7
> 8 ArrayList arrayList2 = new ArrayList(arrayList1.get(0)); //gives error; The constructor ArrayList(Object) is undefined
>
>
> I can not run the code above, because line 8 gives an error. :cry:
> Please have a look at line 6.
> The class of "arrayList1.get(0)" is java.util.ArrayList.
>
> Now have a look at line 8.
> I want to create a new ArrayList based on an existing ArrayList. Line 8 returns an error.
> I think it says that "arrayList1.get(0)" an Object and that it is not possible to create a new arraylist this way.
>
> This is strange!! :? In line 6 "arrayList1.get(0)" is a java.util.ArrayList.
> In line 8 "arrayList1.get(0)" is an Object.
>
> Do you think this is strange or am I missing something???
|
|
|
|
Powered by
FUDForum. Page generated in 0.02166 seconds