This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes serialization deserialization Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "serialization deserialization" Watch "serialization deserialization" New topic
Author

serialization deserialization

gylph knor
Greenhorn

Joined: Jun 12, 2008
Posts: 20
Please have a look at my code and tell me why this complie time error is being thrown


can't i use any method other than the toString() method in my deserialised object?





Error:
___________________________________________________________

H:\java>javac wwe.java
wwe.java:34: cannot find symbol
symbol : method good()
location: class java.lang.Object
System.out.println(fgh.good());
^
1 error

H:\java>






please help!!!

[ June 24, 2008: Message edited by: gylph knor ]
[ June 24, 2008: Message edited by: gylph knor ]
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42047
    
  64
"fgh" is of type "Object" - which does not have a "good" method.

The fact that you're casting it to "wwe" in between doesn't matter - it's still just an Object.

I think you meant to do something like this:

[ June 24, 2008: Message edited by: Ulf Dittmer ]

Ping & DNS - my free Android networking tools app
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18876
    
  40



Well, there are actually many errors in your code. But the one that the compiler is complaining about is....

"fgh" is a reference to an Object instance -- and an Object instance doesn't have a good() method.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
gylph knor
Greenhorn

Joined: Jun 12, 2008
Posts: 20
i still didn't get it ,

when an instance is type casted, how does it still remains the old object?
[ June 24, 2008: Message edited by: gylph knor ]
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42047
    
  64
It doesn't matter what it's cast to if afterwards it's assigned to a variable of type "Object". Because that's all the compiler knows about it - that it is an Object. The cast -as it is used here- really does nothing.
Krishnamoorthy Vuyala Muralidharan
Ranch Hand

Joined: Sep 13, 2005
Posts: 52
Hi

The type casting is fine. The real object to which the Object fgh points to is of type wwe which contains the method good(). This is fine as far as the run-time is concerned but for the compiler it checks for the method good() in the Object fgh. Its is clear for the compiler that the method good() is not present in the class Object so you got the error as a result.

Object fgh = (wwe)oi.readObject;
fgh.good(); // this fails at compile-time as the compile is interested
// only to check fgh(type of Object) contains the method
// good or not. Since there in no such method it fails
// to compile

Hope this helps.

Kris
gylph knor
Greenhorn

Joined: Jun 12, 2008
Posts: 20
OK , now i get it.

thanks a lot!!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: serialization deserialization