Re: Create a JAVA Client/Server app in 5 Minutes
Donkey Hottie wrote:
What warning?
private List<String> list = new ArrayList() ;
list.add(new HashMap<String, Integer>());
gives me a warning, no matter what I use after "new" in the declaration o=
f
"list".
Can you give me an example where the exact type of "new ArrayList()" is
needed?
I can get only warnings, if I declare that ArrayList wrong:
private List<String> list = new ArrayList<Map<String, I=
nteger>>() ;
But new ArrayList() does not fail. And all that java cares is the type of
"list" afterwards. IMHO. (I may be wrong).
Given:
package eegee;
import java.util.ArrayList;
import java.util.List;
public class GenWarning
{
private List<String> list = new ArrayList(); // line 8
public List<String> getList()
{
return this.list;
}
public static void main( String [] args )
{
GenWarning gw = new GenWarning();
gw.getList().add( "foo" );
System.out.println( gw.getList() );
}
}
I get:
$ javac -d ../build eegee/GenWarning.java
Note: eegee\GenWarning.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
$ javac -d ../build -Xlint:unchecked eegee/GenWarning.java
eegee\GenWarning.java:8: warning: [unchecked] unchecked conversion
found : java.util.ArrayList
required: java.util.List<java.lang.String>
private List<String> list = new ArrayList();
^
1 warning
Those warnings.
--
Lew