File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

serialization deserialization

 
gylph knor
Greenhorn
Posts: 20
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Pie
Posts: 42966
73
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"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 ]
 
Henry Wong
author
Marshal
Pie
Posts: 20823
75
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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
 
gylph knor
Greenhorn
Posts: 20
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Pie
Posts: 42966
73
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 20
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK , now i get it.

thanks a lot!!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic