Review your favorite Linux distribution.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 03-22-2005, 01:57 PM   #1
Registered: Apr 2004
Distribution: Slackware 10, Open BSD 3.6, Mac OS 10.3.7, Splack 10 beta
Posts: 393

Rep: Reputation: 30
java objects

How can i tell what type an object is. For example

public Object returnObject() {
return randomObject;

How can i tell what object type it is.
Old 03-22-2005, 02:12 PM   #2
Registered: Sep 2002
Location: Tulsa, OK
Distribution: Slack, baby!
Posts: 349

Rep: Reputation: 33
One way is by using <objectName>.getClass().getName(). I'll continue searching, though, for other info I can find.
Old 03-22-2005, 03:01 PM   #3
Senior Member
Registered: Apr 2003
Location: Toronto, Canada
Distribution: Ubuntu Jaunty (9.04)
Posts: 1,044

Rep: Reputation: 45
If you are writing the code then you should know what kind of an object it is. Otherwise, its very hard to tell because it could be an object from one of the data types in java or an object of some class that someone wrote. For example, a class can be something like:

public class dud() {

   public dud() {
       int x;
       int y;
       String st;
And therefore its hard to find out what type it is. Another dirty way to tell it would be to try and cast it into some other type and if you get an error, you can see what type of data you were trying to convert. Hope this helps
Old 03-23-2005, 06:21 AM   #4
Registered: Sep 2004
Distribution: Slackware 10
Posts: 167

Rep: Reputation: 30
are you truly returning any object type? cause if it is a limited set of objects you could possibly return, you could always validate your objects using instanceof

if (objecta instanceof dud)
or something more dynamic



Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Serialized objects into Strings poeta_boy Programming 7 07-15-2005 12:00 AM
Dynamic creation of Objects in C++ poeta_boy Programming 9 08-02-2004 01:58 PM
java arrays and objects titanium_geek Programming 13 03-07-2004 01:21 PM
lost objects gurra59 Linux - Newbie 4 09-07-2003 04:29 PM
Objects in Java? mikeshn Programming 0 06-11-2002 10:21 AM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:10 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration