Author Topic: Casting Object to float  (Read 5062 times)

Offline JAG0991

  • byte
  • *
  • Posts: 2
    • View Profile
Casting Object to float
« on: April 28, 2012, 12:46:35 am »
First post and hopefully not a stupid one.
I've managed to get the demos working under Linux, created Blender objects, PaulsCode Soundsystem and imported the md2's however I'm stuck on such an irritatingly small problem.

Casting an Object to a Float.  :-\

I'm doing this because of the return array from the World.calcMinDistanceAndObject3D(); Where an object array is returned with a float value[0] and the picked Object3D[1].
I'm trying to test the float value to see if it is Object3D.COLLISION_NONE
I get the error:
Code: [Select]
test.java:138: inconvertible types
found   : java.lang.Object
required: float
float ans = (float)(res[0]);
1 error


After searching the forum where I normally get my answers and having no luck I finally decided to ask ... How?

Thanks in advance!

Offline JAG0991

  • byte
  • *
  • Posts: 2
    • View Profile
Re: Casting Object to float
« Reply #1 on: April 28, 2012, 01:14:44 am »
Ok, Although I would still like to find an answer I have found a workaround. According the the Java Docs the java.lang.Object can be used with Class.equals(Object); which is great for testing if an item has been clicked and the System.out.println(); will happily print out the value but it cant be loaded into a float variable.
So the float distance cant be used in code?


Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Casting Object to float
« Reply #2 on: April 28, 2012, 05:01:12 pm »
float isn't an Object, it's a primitive type. You can't an Object into a float. You habe to use Float instead.