2

When I looked at the API specification default list model it stated the class uses generic. When I went to create an instance of the class, it didn't need it or permit it. How are generics integrated with DefaultListModel, and how can it be used?

Thanks :-)

1 Answer 1

2

You never need to use generics because it's simply a compile time check (see Type Erasure for more details).

Essentially, once your code is compiled, generic type information is stripped away, so it's never necessary for your code to run correctly. Generics simply provide a way for the compiler to perform static checks to make sure that you are using types in a consistent/safe manner.

Sign up to request clarification or add additional context in comments.

4 Comments

I knew that going in, but if I choose to use generics why doesn't it let me?
I solved the issue, I'm using se 6 and in se 6 it's not generic :-(
I assumed it was generic as of se 6 as well
You can't assign a generic type to an instance of a class unless the class definition requires one. There would be no benefit to allowing you to do so since the only benefit is type checking and that benefit comes from the return values and method arguments of the class's functions taking arguments of the generic type.

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.