Casting integers from objects... (and other primitives too)

21 Jun 2013 . posts . Comments
#Java

In Java, if you are 100% sure you’ve got an Integer in the form of an Object and you want to convert it to an “int” type…

Object obj; int val = ((Integer) obj).intValue(); And this works with other primitive data types also.


Me

Anthony is an Australian software engineer and mathematician. As a UTS MBT graduate, Anthony is the technology co-founder of a property and cycling-tech startup and enjoys teaching and learning coding with the Australian startup scene.