• 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

serialization deserialization

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK , now i get it.

thanks a lot!!
reply
    Bookmark Topic Watch Topic
  • New Topic