File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes casting interface to object. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "casting interface to object." Watch "casting interface to object." New topic
Author

casting interface to object.

sreenivas jeenor
Ranch Hand

Joined: Jan 09, 2005
Posts: 125
Hi ,

i am working on this code.

how to achieve runtime casting for the following code


Similarly other classes like XPN, XCN implements composite.

in the Main file the code is..
-----------------------


--------------------

help me...
Hunter McMillen
Ranch Hand

Joined: Mar 13, 2009
Posts: 492

Have you tried:



Also, in your Varies class what is the type of 'data' that you return from getData()?

Hunter


"If the facts don't fit the theory, get new facts" --Albert Einstein
sreenivas jeenor
Ranch Hand

Joined: Jan 09, 2005
Posts: 125
Returns the data contained by this instance of Varies. Returns a GenericPrimitive unless setData() has been called.
Hunter McMillen
Ranch Hand

Joined: Mar 13, 2009
Posts: 492

did the example code I posted work? was there an error?

Hunter
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10170
    
    8

Sreenivas,
In future, while posting code, please UseCodeTags
I have edited and added them in your post. As you can see the tags make the code much more easy to read and understand.


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
sreenivas jeenor
Ranch Hand

Joined: Jan 09, 2005
Posts: 125
private Type data;

here is



its shows an error java.lang.ClassCastException: GenericComposite cannot be cast
to CWE
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 37990
    
  22
I would have thought that requiring so many casts implies a design error somewhere.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Campbell Ritchie wrote:I would have thought that requiring so many casts implies a design error somewhere.


To me that makes it look like the design should involve Generics in some way. Something perhaps like this:
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 37990
    
  22
Yes, Paul C, that looks a lot better.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: casting interface to object.
 
Similar Threads
Casting problem
Question about casting to String
interface and class reference variable casting
Cast expression
ExamLab Question