Re: Create a JAVA Client/Server app in 5 Minutes
Andreas Leitgeb wrote:
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()?
Well, I don't need to use an additional method "ServerConfig" ...
I would like to go the standart way to use a constructor to construct
an object
All NewObject() could do, is throw some exception at *runtime* if some
given interface wasn't implemented by that class.
yes if an object is created the following check is done
from context_java.c function Java_MqS_Main_pCreate
if ((*env)->IsInstanceOf(env, self, Class_IClient) == JNI_FALSE) {
JavaErrorSave("interface 'MqS.IClient', 'MqS.IServer' or 'MqS.IFilter'
is required");
return;
}
that is it, to be a MqS class you have to add on of the interfaces
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.)
if, for some kind of reason, the interface method is not available
a runtime error is raised that's no problem -> without ServerConfig
I can not start a server that's it ...
The problem is that the programmer, if he compile the code he get
at compile-time error saying:
hey you are using "IServer" and you propably want to create
a server but method .... or constructor ... is required
to do that -> please add them and continue with your work
as i understand an interface is a help to the programmer to
just provide the necessary functions it's a help to do the
right stuff nothing more
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.
}
}