aspose file tools*
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


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
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: 39547
    
  27
"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 - updated with new look and Ping home screen widget
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18116
    
  39



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: 39547
    
  27
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
 
Similar Threads
print statements not working in serialization code
need help with garbage collector
(De)Serialization question
about private void writeObject ( ObjectOutputStream os )
Simple question - char