Results 1 to 5 of 5

Thread: Class cast

  1. #1
    bkraut is offline Member
    Join Date
    Feb 2012
    Posts
    3
    Rep Power
    0

    Default Class cast

    Hi,

    I'm searching for a way to cast between two class entities. I'm writing a CRM with Target and Lead classes. Both are subclasses from BaceContact class each with additional fields.
    I have to somehow cast between them. Is it the only way to set manually all the fields from Target to Lead?
    I'd also like to keep the same key if possible, so all the documents attached to Target can will be preserved. From my point of view Target can be removed from the table.

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

  3. #3
    bkraut is offline Member
    Join Date
    Feb 2012
    Posts
    3
    Rep Power
    0

    Default Re: Class cast

    Hi,

    I have to convert (better as cast) from Target to Lead. As Target and Lead use same superclass BaseContact. Now - I would like to write method, which would convert a Target to a Lead.

    I have several dependent entities like Attachments, which are connected directly to BaseContact superclass. My process should remove Target and convert it into a Lead, keeping an id of the Target, so all the dependent entities does not need to change.

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default Re: Class cast

    Well the casting part is easy -- you can't do it so don't try. But the other issues sound as if it may be best solved via one or more design patterns. Perhaps you can create a class that has holds the basic data and has the basic shared behaviors of both Target and Lead, and use a Command Pattern and perhaps dependency injection to swap in and out modules that allow the class to exhibit Target or Lead behaviors.

  5. #5
    bkraut is offline Member
    Join Date
    Feb 2012
    Posts
    3
    Rep Power
    0

    Default Re: Class cast

    I was also sure that cast is not possible. Thanks for the answer I'll think about it.

Similar Threads

  1. Need Help with Class Cast Exception
    By soxfan714 in forum New To Java
    Replies: 2
    Last Post: 11-03-2011, 04:33 PM
  2. Class Cast exception
    By henry123 in forum Advanced Java
    Replies: 4
    Last Post: 02-15-2011, 11:42 AM
  3. Class cast issue
    By AedonetLIRA in forum New To Java
    Replies: 5
    Last Post: 11-19-2010, 04:34 PM
  4. Cast own class to FrameView
    By Luxpsycho in forum AWT / Swing
    Replies: 0
    Last Post: 07-16-2010, 10:13 AM
  5. class cast exception
    By venkatallu in forum New To Java
    Replies: 2
    Last Post: 09-02-2008, 09:50 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •