Results 1 to 8 of 8
- 01-08-2010, 07:27 AM #1
Member
- Join Date
- Dec 2009
- Posts
- 6
- Rep Power
- 0
Wrap an object into another object type
Now I got 2 objects which from different classes ClassA and ClassB but they have exactly same attributes. ClassA and ClassB is not interface. Assume that ClassB can not be modify.
Can wrapper wrap classB into classA? For what I know wrapper can wrap primitive class into object type. As for reflection can retireve classB field and set it to classA but due to the security concern, can wrapper do that?
public ClassA retrieveDetails(int id) {
ClassA classA = null;
ClassB classB = null;
// Error occur here classB.retrieveDetails(id) this method return ClassB instead of ClassA
classA = classB.retrieveDetails(id);
return classA;
}
- 01-08-2010, 07:42 AM #2
Senior Member
- Join Date
- Aug 2009
- Posts
- 2,388
- Rep Power
- 6
- 01-08-2010, 07:43 AM #3
Member
- Join Date
- Dec 2009
- Posts
- 6
- Rep Power
- 0
Ya for some reason must have this 2 classes.
- 01-08-2010, 11:03 PM #4
if ClassB is a subclass of ClassA, then yes.
- 01-08-2010, 11:27 PM #5
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,547
- Rep Power
- 11
Please, it's not my intention to offend you, but that won't do.
When r\d*x asks why you want to do such a thing, that's not to be nosey. It's because he or she wants to help: but, like the rest of us, can't really help unless they know what it is that you are trying to do. There is a chance that you are going about whatever it is you are doing the wrong way. Rather than "help" you do it wrongly it's only natural that you would be asked what your aim is in doing this.
And "for some reason" just isn't an answer.
- 01-09-2010, 10:01 AM #6
Member
- Join Date
- Dec 2009
- Posts
- 6
- Rep Power
- 0
Thanks, Lil_Aziz1 since classB must be subclass of classA i think wrapper can not solve my problem. Thanks for your answer.
- 01-09-2010, 10:58 AM #7
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,408
- Blog Entries
- 7
- Rep Power
- 17
This shows once more: code to the interface, not to the implementation; because your client code depends on ClassA or ClassB you are stuck, i.e. you can't give them a wrapper that necessarily has to be another class and it can't extend both from ClassA and ClassB.
kind regards,
Jos
- 01-09-2010, 04:35 PM #8
Member
- Join Date
- Jul 2009
- Posts
- 35
- Rep Power
- 0
Similar Threads
-
using instanceof to get Object type and parent type?
By xcallmejudasx in forum New To JavaReplies: 2Last Post: 11-06-2008, 06:24 PM -
List views, a type of object
By Leprechaun in forum New To JavaReplies: 2Last Post: 02-06-2008, 03:07 AM -
Need help with creating array of type object
By riz618 in forum New To JavaReplies: 3Last Post: 01-29-2008, 06:14 AM -
Getting object type
By gapper in forum New To JavaReplies: 1Last Post: 01-20-2008, 08:49 AM -
Creating object of Type Object class
By venkatv in forum New To JavaReplies: 3Last Post: 07-17-2007, 03:33 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks