0

my problem is that I create java code with Freemarker and I need the type of a variable, which is not initialized. I need the type, because there are specified methods for each class type.

So I have a custom class that implements from Parcelable.

int id;
  public MyClass(Parcel parcel) {   
    if(id.getClass().toString().equals("Long")) id=parcel.readLong();
    if(id.getClass().toString().equals("String")) id=parcel.readString();
  }

I know there is a method readValue() but that solved not my problem, because the same problem is, if I want to write the Objects.

So that is the main problem. I hope you understand this and you can help.

Thanks

pinoxxio
  • 38
  • 7
  • 1
    It's really not clear what you mean here - `id` is of type `int`, so you can't call `getClass()` to start with. Please clarify. – Jon Skeet Jan 16 '13 at 16:02
  • possible duplicate of [Get type of an object with an object of null?](http://stackoverflow.com/questions/20378132/get-type-of-an-object-with-an-object-of-null) – Raedwald Mar 12 '15 at 08:03

1 Answers1

0

It's not very clear what you mean but I think you are looking for

instanceof

MariusBudin
  • 1,277
  • 1
  • 10
  • 21
  • Thanks for your help, but I think it is not possibile to get class type, because in this case id referenced on null, and that is not a type. – pinoxxio Jan 19 '13 at 12:07