Home Ask Login Register

Developers Planet

Your answer is one click away!

Tander 2 weeks ago

How to check Object is of a Class<T>

Given the following java class

public class Resource<T> {


How would I check what <T> is? As it doesn't exist at runtime.

An example method, where Resource is used:

  public void onChanged(@Nullable Resource objectResource) {
       //How do I check that objectResource is a Resource<SomeObject> 
       // Vs Resource<SomeOtherObject> ? 


Rahul Tripathi 2 weeks ago

You can try ti use instanceof

if (myobj instanceof myClass) {
//your code

Post Status

Asked in 2 weeks ago
Viewed 3,209 times
Voted 14
Answered 1 times


Leave an answer

Quote of the day: live life