Re: Create a JAVA Client/Server app in 5 Minutes
Andreas Otto <aotto1968@onlinehome.de> wrote:
but why exist the following JNI function
http://java.sun.com/javase/6/docs/technotes/guides/jni/spec/functions.html#wp4517
this is totally mad if a constructor is not "interface-able"
If an Interface *could* enforce a particular constructor for all it's
implementors, what good would it do you with NewObject()?
All NewObject() could do, is throw some exception at *runtime* if some
given interface wasn't implemented by that class. However at runtime
it can just simply check for presence of the constructor directly.
(And it would have to do that, anyway, for some subtle reasons
concerning interfaces that got enhanced and recompiled since the
implementing class was compiled - even interfaces in the Java
standard libraray get extended casually.)
Something I don't understand:
private List<List<String>> data;
Oh, you have nested lists. It's slightly different here:
private List<? extends List<String>> data;
that's what i don't understand too because i had a working solution with
ArrayList fine but why i should change it to List ?
Lew already gave the correct answer to the "why", and also corrected
my thinko with respect to <? extends List<...>> in the var-declaration.
--- snip to end ---
import java.util.*;
public class TestClass {
private List<List<String>> data;
TestClass() {
data=new ArrayList<List<String>>();
data.add( new ArrayList<String>() );
data.get(0).add( "Sauerkraut" );
}
void copyFrom( List<? extends List<String>> otherData ) {
data.clear(); data.addAll(otherData);
}
static {
TestClass t1 =new TestClass();
TestClass t2 =new TestClass();
t1.copyFrom(t2.data); // List<List<String>>-typed
t2.copyFrom( new ArrayList<ArrayList<String>>() );
// works, too.
}
}