0

Someone knows why this doesn't work?

public class ArrayList<E extends EXTDBinterface<T>> 
    extends java.util.ArrayList<E> implements List<E>,
    RandomAccess, Cloneable, java.io.Serializable {}

Eclipse complains about T not being resolved to a type... Is it impossible to extend the ArrayList class for types extending EXTDBinterface<T>? The point is I would like to use T inside the class, but sadly only this works:

public class ArrayList<E extends EXTDBinterface> 
    extends java.util.ArrayList<E> implements List<E>,
    RandomAccess, Cloneable, java.io.Serializable {}

but then how to get the generic type T of EXTDBinterface at runtime...?

3 Answers 3

3

First doesn't work cause you didn't set type T. Also you don't need to extend and implement all stuff again cause ArrayList has had this yet. Write, for example:

class ArrayList<T,E extends EXTDBinterface<T>> 
extends java.util.ArrayList<E>{}
Sign up to request clarification or add additional context in comments.

1 Comment

Yes thanks for the additional correction of removing the implements! This is the correct answer, but don't know if you or GanGnaMStYleOverFlowErroR was first ^^
0

how to get the generic type T of EXTDBinterface at runtime

You can't do that given that Java makes use of type erasure. If you need the actual type, then you'll have to pass that in (normally as a Class-typed parameter)

2 Comments

Thank you for your answer. Sadly, I think you're right... Checking out crazy solutions here ^^. None seem to work...
Check out bellum's answer. Seems to do what I want!
0

You have to define T as the type argument for the class

public class ArrayList<T, E extends EXTDBinterface<T>> 
    extends java.util.ArrayList<E> implements List<E>,
    RandomAccess, Cloneable, java.io.Serializable {}

3 Comments

Thank you for your answer. Eclipse complains even more with this ^^. But would it compile?
umm, i compiled fine for me, what does eclipse complain about ?
Thank you for your answer. Yes, after your edit it works! But did you edit before or after bellum's answer? Cause it says 43 minutes both ^^

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.