Help coderanch get a
new server
by contributing to the fundraiser
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Primitive type

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can anyone tell if it is possible to check if a variable is of a primitive type?
i.e
 
Ranch Hand
Posts: 269
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 1055
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Did Steve tell you that? Fuh - Steve. Just look at this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/t/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic