Re: Create a JAVA Client/Server app in 5 Minutes
Andreas Otto wrote:
if I change to
private List<List<String>> data;
as you mentioned ... I get the following error
That's not precisely what I mentioned.
CLASSPATH=.:./.:$CLASSPATH
What is "./."?
And since you're using the "-classpath" option you don't need the
CLASSPATH envar.
javac -d . -classpath "../javamsgque:." -Xlint:unchecked Filter1b.jav=
a
Filter1b.java:29: incompatible types
found : java.util.ArrayList<java.util.ArrayList<java.lang.String>>
required: java.util.List<java.util.List<java.lang.String>>
data = new ArrayList<ArrayList<String>>();
^
Andreas Leitgeb gave one way to declare this. Another way is:
private List <List <String>> data =
new ArrayList <List <String>> ();
The difference is that Andreas's suggested form
private List <? extends List <String>> data =
new ArrayList <? extends List <String>> ();
requires that all nested 'List's be of the same concrete type, and the
way without 'extends' allows each outer 'List' element to be a
different concrete kind of 'List'.
It is well worth studying generics to the point where you get this.
Filter1b.java:43: incompatible types
found : java.util.List<java.lang.String>
required: java.util.ArrayList<java.lang.String>
for (ArrayList<String> d: data) {
^
2 errors
In a 'for-each' loop, the type of the loop variable must match the
base type of the 'Iterable'. In this case, you needed
for ( List <String> d : data )
List is in 1.6 an abstract class -> I can not create a List object !!
'List' in Java 1.2 onward is an interface. It is not an abstract
class. Regardless, you can, indeed, create a 'List' object; you just
have to provide a concrete subtype to the 'new' operator. This is
both fundamental Java programming and fundamental object-oriented
programming. Program to the interface, not the implementation.
For example,
private List <List <String>> data =
new ArrayList <List <String>> ();
creates a 'List' object. (!!)
--
Lew