java - Generics in Constructor Parameters -
i know silly question since once knew stuff that. have hard time getting done. have constructor class wich should arraylist wich filled objects implement interface called collisionobserver. here constructor-head:
public cursor(gl gl, libraryfinger finger, vector direction, float radius, int index, arraylist<t extends collisionobserver> observerlist)
can tell me make big mistake? tried arraylist<collisionobserver>
too, doesn't work too, since when call constructor objects implement collisionobserver error message says constructor undifined.
ok, here complete cursor class:
public class cursor implements collisionsubject{ private vector direction; private gl gl; private float radius; private libraryfinger finger; private glut glut; protected static float[] sphere_center = new float[3]; private arraylist<collisionobserver> observer = new arraylist<collisionobserver>(); public cursor(gl gl, libraryfinger finger, vector direction, float radius, int index, arraylist<t extends collisionobserver> observerlist){ this.gl = gl; this.finger = finger; this.direction = direction; this.radius = radius; glut = new glut(); //finetuning fingermovements! vector delivered leaplistener considered //raw-data. has adjusted environment in fingertracking used. sphere_center[0] = (float) (finger.getx()/15); sphere_center[1] = (float) ((finger.gety()/20)*-1); sphere_center[2] = (float) (finger.getz()/5); gl.gltranslatef(sphere_center[0], sphere_center[1], sphere_center[2]); gl.glenable(gl.gl_cull_face); gl.glcullface(gl.gl_back); gl.glcolor3f(0.757f, 0.804f, 0.804f); glut.glutsolidsphere(radius, 16, 16); (int = 0; < index; i++){ registercollisionobserver(observerlist.get(i)); } myposition(); } @override public void registercollisionobserver(collisionobserver o) { observer.add(o); } @override public void removecollisionobserver(collisionobserver o) { if (!observer.isempty()) { int = observer.indexof(o); if (i >= 0) observer.remove(i); } } @override public void myposition() { (int = 0; < observer.size(); i++) { collisionobserver o = observer.get(i); o.collision(finger, direction, radius); } }
and here how invoke constructor. in 2 different classes. first class:
private arraylist<picture> piclist = new arraylist<picture>();
the type "picture" implements interface collisionobserver
cursor finger = new cursor(gl, lfl[i], listener.getfl().get(i).direction(), 0.5f, piclist.size(), piclist);
same thing class two. type shelf implements collisionobserver interface:
private arraylist<shelf> shelflist = new arraylist<shelf>(); cursor finger = new cursor(gl, lfl[i], listener.getfl().get(i).direction(), 0.5f, shelflist.size(), shelflist);
in 1 of constructor parameters, have declared:
arraylist<t extends collisionobserver>
where'd t
come from? if want have arraylist
contain elements type-bound class, use of t
appropriate here.
from seems like, want list of objects implement collisionobserver
, declaration want:
arraylist<? extends collisionobserver>
Comments
Post a Comment