File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Primitive type Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Primitive type" Watch "Primitive type" New topic
Author

Primitive type

nate saider
Greenhorn

Joined: Jun 24, 2002
Posts: 17
Can anyone tell if it is possible to check if a variable is of a primitive type?
i.e
Wilfried LAURENT
Ranch Hand

Joined: Jul 13, 2001
Posts: 269
Hi,
it is not possible to have an attribute variablevariable, which could be either an 'int' or a 'String' depending on some conditions.
How would you declare it?
What you can do is to have an attribute .variablevariable , which can either be instantiated as an java.lang.Integer or a java.lang.String
Then you can test the type of your object with

But i doubt that your request fits the design good practice
W.
[ July 08, 2002: Message edited by: Wilfried LAURENT ]
nate saider
Greenhorn

Joined: Jun 24, 2002
Posts: 17
Um... thanks. That is actually helpful.
What's not good design practice about it?
It gets the job done and it's homework for a professor who didn't teach us Java, but expects us to know it even though it is not a requirement for the class. I say it is GREAT design practice for someone who learned a semblence of java in 4 days.
well, it's 4 am and time for bed. Thanks again
Anthony Villanueva
Ranch Hand

Joined: Mar 22, 2002
Posts: 1055
Ideally, a client class should not access the data representation, i.e. (its instance variables) of a class directly. They should be declared private, with public accessor methods. The type of the variable should be clear from the return value of the accessor signature.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Primitive type