How can I casting from parent class to children class

Dear,
Could someone help me to casting from parent class to children class.
I have class like this
class parent{
String name;
String id;
public String getId() {
return id;
public void setId(String id) {
this.id = id;
public String getName() {
return name;
public void setName(String name) {
this.name = name;
class children extends parent{
String address;
public String getAddress() {
return address;
public void setAddress(String address) {
this.address = address;
public children() {
public children(parent p) {
//Do init super class here
In the constructor
public children(parent p) {
//Do init super class here
I like to init super class by object p (this is instance of parent class). The way to do is using:
public children(parent p) {
super.setId(p.getId());
super.setName(p.getName());
But I don't like this, because, for example I have parent class with over 30 proberties, it take time to do like that.
There are any way to use super operation to init parent class, for example super = p;
Could you show me the way.
Thanks alot

If I understand your question correctly, you are in need of a copy constructor for you class Parent. A copy constructor behaves like this:
   Parent one = new Parent();
   one.setName("...");
   //... and all other properties of interest
   Parent two = new Parent(one);
   //Now two != one, but one.getName().equals(two.getName) for property name and all othersThe copy constructor is programmed in the Parent class, more later. Then for your child class you can use it as follows
   public class Children extends Parent {
       public Children(Parent p) {
          super(p);
   }There are at least 3 ways of programming a copy constructor:
1. Just bite the bullet: type the assignment for each field this.name = p.getName()
2. Use reflection to find all common setters/getters dynamically and assign using them
3. Use a code generator that uses 2 to give you the code for solution 1 for you to paste in.
If you find doing this a lot, there are frameworks that can do these mappings, like Dozer
(PS be carefull with Date fields, don't copy the reference but create a new and equals instance, the dirty way would be this.birthdate = new Date(p.getBirthdate.getTime()); )

Similar Messages

  • How to copy data from parent member to children members?

    Hello,
    I'm entering data on a parent level in a form, and I'm running a rule to copy the data to the below children of the selected member.
    It's running, but it's taking very long time. As I'm writing a normal member range having the children, and inside the script its having an equation of account=account->parent.
    I know that the system template is very fast, but it copies only to one member. Can we use this copy template or any similar fast way to copy from each parent to the below children ?
    Thank you.

    Here below the script, it was working in 3 seconds before adding the copying to the "DIMX" dimension, although the parent i selected in the form contains only 7 children, so I don't know why it made things harder.. so, that's why I'm thinking of using something like the copy template or something.
    The commands in the standard set used are:
    SET LCOKBLOCK HIGH;
    SET CACHE HIGH;
    SET UPDATECALC OFF;
    SET CLEARUPDATESTATUS OFF;
    SET CALCPARALLEL 3;
    SET AGGMISSING ON;
    SET CREATENONMISSINGBLK ON;
    %Script(name:="Standard Set Commands",application:="PRJ",plantype:="Plan1")
    FIX
    (/*DIM:Account*/"601010002","601010003","601010004","601010005","601010006","601010007","601010010","601010011","601010012","601010013","601010014","601010015","601010017","601010018","601010019","601010020","601010021","601020003","601020004","601020005","601030001","601030002","601030004","601030005","601030006","601030007","601030008","601030009","601030010","601030011","601030012","601010003","601010016","601030003",/*DIM:Entity*/@Relative({RTP_Entity},0),/*DIM:Currency*/"AED",/*DIM:DIMX*/@Relative({RTP_DIMX},0),/*DIM:Dim_Custom*/"DIM_7001")
    FIX ( /*DIM:Periods*/&V_First_Forecast:&V_Last_Forecast,/*DIM:Years*/&V_CURRENT_YEAR, /*DIM:Scenario*/"Forecast")
    /*STARTCOMPONENT:SCRIPT*/
    Version
    &V_WORKING_VERSION = &V_TARGET_VERSION->{RTP_Entity}->{RTP_DIMX};
    /*ENDCOMPONENT*/
    ENDFIX
    FIX ( /*DIM:Periods*/&V_First_Budget:&V_Last_Budget,/*DIM:Years*/&V_BUDGET_YEAR, /*DIM:Scenario*/"Budget")
    /*STARTCOMPONENT:SCRIPT*/
    Version
    &V_WORKING_VERSION = &V_TARGET_VERSION->{RTP_Entity}->{RTP_DIMX};
    /*ENDCOMPONENT*/
    ENDFIX
    ENDFIX
    Awaiting your feedback.
    Thank you.
    Edited by: user7304950 on Sep 14, 2012 7:41 AM

  • How can I cast in runtime

    Hi,
    I have read many pages of this forum, but I haven't found answer to my problem. It is very simple.
    Object o = new JDialog();
    Class cl = JDialog.class;
    JDialog jd = (JDialog)o;
    jd = cl.cast(o);The last row go to compile time error, why? How can I cast, if my class is only available by a variable?
    Thanks

    _dnoyeB wrote:
    There is no point in casting to a class if you don't plan to call a specific method on that class' interface.
    Why are you casting to a class and you don't even know what it is? I can see not knowing what you are casting from, but not knowing what you are casting too makes no sense.Yes, I want to call a method of a given class, but - in the particulat context - only what I have is an instance (object) of that class. I didn't want to write all of my use case rather the final question to have to solve. I thought the object.cast() is the solution, but it don't work. Why? That is the question I am waiting for.
    It think there is an interesting situation: if object.cast() don't operate, what is it's task? My knowledge may be not too much.

  • How Can I Print from my Microsoft Surface Running Windows 8 RT?

    How Can I Print from my Microsoft Surface Running Windows 8 RT?
    Most new wireless printers won’t have a problem printing from the Microsoft Surface with Windows 8 RT.  All you should have to do for these printers is tell them to print and they will.  Older wireless, Ethernet, and USB printers might not have an officially supported driver in Windows 8 RT, but there is a way to get the printers working.  There are different requirements depending on how the printer is being connected to the Surface. 
    Note:  All steps below are only for PhotoSmart, OfficeJet, DeskJet, and other HP Inkjet printers.  These steps are not for Laserjet printers or printers from other manufacturers.  These steps may not work for all Inkjet printers.  If these steps don’t work, try different drivers from the list until you find one that will work (you’ll understand what I mean once you follow the steps below).  If none of the drivers work, your printer will not work with the Surface.
    For networked printers (wireless or Ethernet), all you need is either the Surface keyboard, or an external USB keyboard to connect to the Surface.  This just makes anything you have to type easier to type.  You will also need to have the Surface and the printer connected to the same network. 
    Starting from the right edge, swipe your finger left on the Surface screen to bring up the Charms bar.
    Touch Search.
    Below the Search Box, touch Settings.
    In the search Box, type Devices and Printers.
    Touch Devices and Printers.
    Touch Add a Printer.
    Touch “My printer is not listed”.
    Select the TCP/IP option and touch Next.
    Enter the printer’s IP address and touch Next.  Note:  You can get this from the printer’s Network Configuration Page, or from your router’s DHCP list.
    The Surface will locate the printer and try to install it.  The install will fail and the Surface will ask you what you want to do, search the internet for the driver, or manually install the driver.  Choose to install the driver yourself.
    Touch “I want to choose from a list of drivers”.
    If no drivers appear in the list, make sure the box next to “Show compatible drivers” is not checked.
    Choose HP from the Manufacture list.
    Choose DeskJet PCL 3 Class Driver from the Drivers list.  If that driver doesn't work, try using the Photosmart PCL3 driver, or the Officejet PCL 3 driver.  (Thank you JonW for letting me know about these other alternates. )
    Touch Next.
    Touch Finish.
    Test printing.
    For USB connected printers, you will need a USB cord to attach the printer to the computer.
    Connect the printer to the computer via USB.
    Windows will try to find the drivers but will not be able to.
    Here Windows may ask you if you want to choose the driver to install.  If it does skip to step 14 below.
    Starting from the right edge, swipe your finger left on the Surface screen to bring up the Charms bar.
    Touch Search.
    Under the Search box, touch Settings.
    In the Search box, type Device Manager.
    Touch Device Manager.
    Touch View and select Show Hidden.
    Search for the printer in the Device Manager.  It should be under Other Devices with a yellow caution sign beside it.
    Select the printer from the list.
    Touch Action.
    Touch Update Driver, or Install whichever one it displays.
    The Surface will ask you what you want to do, search the internet for the driver, or manually install the driver.  Choose to install the driver yourself.
    Touch “I want to choose from a list of drivers”.
    If no drivers appear in the list, make sure the box next to “Show compatible drivers” is not checked.
    Choose HP from the Manufacture list.
    Choose DeskJet PCL 3 Class Driver from the Drivers list.  If that driver doesn't work, try using the Photosmart PCL3 driver, or the Officejet PCL 3 driver.  (Thank you JonW for letting me know about these other alternates. )
    Touch Next.
    Touch Finish.
    Test printing.
    -------------How do I give Kudos? | How do I mark a post as Solved? --------------------------------------------------------
    This question was solved.
    View Solution.

    Hope this helps.  
    -------------How do I give Kudos? | How do I mark a post as Solved? --------------------------------------------------------

  • The float in windows option is grey and not accessable ? How can I copy from one image to another ? Elements 11

    The float all in windows option is grey and not accessible ? How can I copy from one image to another ? Elements 11

    You really are not getting this.
    "I guess I am still completely shocked that as a parent we can't download something for everyone to use."
    Why do you continue to think this although we keep telling you that this is not the case.
    You do NOT have to purchase anything twice.  You can share the music with as many ipods as you like in your household.
    The ipods are designed to sync with your computer regularly.  You should have been syncing these other ipods with your computer all along, thus transferring the purchases to your computer where that music can be synced to as many ipods as you like.
    Take on of the ipods with the music in it.  Open itunes on your computer.  Plug in the ipod.  Do not sync.  Click File>Transfer Purchases  This will transfer the purchases from the ipod to the computer.  Make sure that you have authorized your account on the computer:  here are directions for that. http://support.apple.com/kb/HT1420
    Unplug the ipod.
    Plug in the other ipod with purchased music.  Do not sync.  Click File>Transfer Purchases  This will transfer purchases from the ipod to the computer.
    You can now plug in any of the ipods, select what you want to sync and sync.
    Have a look at the manual for the ipod.  http://manuals.info.apple.com/en_US/iPod_touch_iOS4_User_Guide.pdf

  • Can not cast from object to int

    Hi All,
    I have the following bunch of code
    Session session;
              session = getSessionFactory().openSession();
              Query query;
              int MaxPageId = 0;
              List list;
              try{
                   query = session.createQuery("select max(emp.id) from EmpBean emp");
                   list = query.list();
                   MaxPageId = (int) list.get(0);
                   return MaxPageId;
              catch(Exception e){
                   System.out.println(e.getMessage());
              return MaxPageId;
    The query executed successfully but when i get the max id in a integer variable by the following statement
    MaxPageId = (int) list.get(0);
    I get the following error "can not cast from object to int"
    Please suggest for the same.
    -Thanks

    Cast to an Integer, not an int, and let autoboxing turn the Integer into an int.
    int maxPageId;
    maxPageId = (Integer) list.get(0);You can't cast objects into primitives.
    Autoboxing isn't casting.
    And use Java naming conventions. Local variables start with a lower-case letter.

  • How can I steam from my early 2011 15-inch Mac Book Pro to my 2007 Samsung TV?

    I have an early 2011, 15-inch Mac Book Pro Software  OS X 10.9.5 (13F34). It does not have an HDMI port. I have a Samsung TV I bought in 2007 (Model LN-4061F). How can I stream from laptop to my TV? My laptop does not have an HDMI port. I've read I can buy an adapter, but I'm not sure what to buy.
    -Does Apple make them?
    -Are knockoff adapters "safe" to use with my laptop, and are they reliable/have a good quality connection?
    -How much do they cost (I've seen cheap ones on Amazon)?
    -What kind should I buy?
    -Will my laptop stream in HD? 
    I'm new to the community, so hoping someone can advise me how to do this. We also have a Roku, but I'm looking to stream DVDs and directly from TV network websites. 
    Thanks for your help!

    You will have to use the  minidisplay port to connect to the TV.  Assuming that the TV has an HDMI port, you will need a cable such as this:
    http://www.monoprice.com/Product?seq=1&kpid=9476&format=2&p_id=9476&CAWELAID=164 2113595&CAGPSPN=pla%26catargetid=320013720000066114%26cadevice=c&gclid=CJHTtbyQ0 8MCFRQ2aQod14cABw
    With this, you eliminate the need for an adapter.
    Ciao.

  • How can I switch from auto_login wallet to password-protected encryption wallet in 12c  ?

    How can I switch from auto_login wallet to password-protected encryption wallet in 12c
    --Now the autologin wallet is in effect
    SQL> select * from v$encryption_wallet
      2  ;
    WRL_TYPE
    WRL_PARAMETER
    STATUS       WALLET_TYPE    WALLET_OR FULLY_BAC
        CON_ID
    FILE
    /acfs3/wallet
    OPEN       AUTOLOGIN    SINGLE    NO
      0
    --I need to export the keys and it informs me to use password-based keystore
    SQL> ADMINISTER KEY MANAGEMENT export KEYS with secret tde_1234 to '/home/oracle/dumpdir/orapdba.wallet' IDENTIFIED BY "tde_1234";
    ADMINISTER KEY MANAGEMENT export KEYS with secret tde_1234 to '/home/oracle/dumpdir/orapdba.wallet' IDENTIFIED BY "tde_1234"
    ERROR at line 1:
    ORA-28417: password-based keystore is not open
    --So I try to close the autologin keystore and open the password-based keystore, but the autologin keystore cannot be closed
    SQL>  administer key management set keystore close;
    administer key management set keystore close
    ERROR at line 1:
    ORA-28365: wallet is not open
    SQL> administer key management set keystore open identified by "tde_1234";
    administer key management set keystore open identified by "tde_1234"
    ERROR at line 1:
    ORA-28354: Encryption wallet, auto login wallet, or HSM is already open
    So My question is
    How to switch from auto_login keystore to password-protected keystore ?

    Remove the cwallet.sso file and check the wallet status in v$encryption_wallet.
    If it is not opened, try to open it with administer key statement.
    Check the status again.

  • HT201320 How can I switch from one email user to another?

    How can I switch from one email account to another?

    You have to select between the two accounts in the mail app.
    Say for instance that you are reading an email in your XYZ email account. Tap the button in the upper left corner of the mail app to back out all the way to where you can see all of the email accounts.... Tap InBox, then tap XYZ email Account and that will take you back to the main MailBoxes window.
    Is that what you want to know? There is no way to simply "toggle" between the two accounts.

  • How can I select from drop-down list and jumping to selected subform?

    I using LC Designer ES2 vers 9. Developing XDP. How can I Select from a drop-down list the appropriate selected subform (jumping to the selected subform on the page)?
    drop-down list...A (jump to subform1)
                             B (jump to subform2)
                             C (jump to subform3)
    subform1
    subform2
    subform3
    ....end of form

    Hi,
    you cannot set focus on a subform but on a field, as only interactive objects can be focussed.
    From a dropdowns exit event the script will look this way:
    switch (this.rawValue) {
              case "A" : xfa.host.setFocus("form1.page2.field1"); break;
              case "B" : xfa.host.setFocus("form1.page2.field1"); break;

  • How can I stream from my macmini to my apple tv

    How can I stream from my desk top to my apple tv. My Wi-Fi network is up and working and I'm able to watch all the netflix, youtube and hulu content endlessly. But how can I also stream directly from my dektop?

    Thanks diesel vdub. I didn't know it was there sitting right on top. I got this new macmini end of april and still discovering all kinds of stuff on it. You are Golden!! Thank you until next time.

  • How can I print from my iPad through my Mac Book Pro which is connected to a printer?  I was told I could do this.

    How can I print from my iPad through my Mac Book Pro which is connected to a printer?  I was told I could do this when the iPad and Mac Book Pro are synched together.

    Antique lady wrote:
    So If I download Printopia on my Mac Book Pro, do I go to iTunes to somehow connect the computer and the iPad? 
    No.
    Printopia (running on your Mac) connects the iPad to your printer.

  • How can I change from useing an english keyboard to a French one

    how can I change from english to french

    Take your stylus and tap and hold on the analog clock and you will get a drop down list with two choices analog or digital. Choose digital.
    Post relates to: Centro (Sprint)

  • How can I change from a free account to a paid account?

    How can I change from a free account to a paid account?

    Tom gave you the answer to your question. 
    if you want a Paid book account, follow the process outlined in the link supplied.
    Apple iBooks store set out these requirements and they do not deviate from them for Individuals.
    You need a new email address for a new account. You need an EIN USA tax file number if you are not a US citizen or US resident. You need to submit bank and credit card details...these can be the same as your iTunes account.
    However much you find the requirements difficult, Apple do not make exceptions.

  • How can I access my parents iCloud account remotely to assist with photo management and printing?

    How can I access my parents iCloud account remotely to assist with photo management and printing?

    I tried that without any luck. I was hoping I could get Apple to reset it for me or delete the account so I could recreate it or at least tell me what is listed as my birth date, the security question answer.

Maybe you are looking for

  • Urgent help with If statement please!

    HI Everyone Was wondering if anyone can tell me why flash seems to be ignoring my If Statements, every time I try to use one it ignores the condition and just actions the command. Its driving me crazy. I'm sure I must be doing something wrong I just

  • At a loss for what preset to use in new project

    Given the following .mov file.  What preset should I use?  I have tried all sort of them...randomly...when I render them most of the time there is no sound even though the video looks good.  Any suggestions on a preset and reasoning WOULD BE SO APPRE

  • File Content Conversion for Multi Hierarchical Structure for Sender Adapter

    Hi Gurus, My text file is coming as Header,filed1,field2(Occurrence=1) Content,field3,field4(Occurrence =1-Unbounded) Detail,field4,field5(Occurrence = 1-unbounded) Trailer,fieldN(Occurrence=1) My requirement is to write a file content conversion, so

  • Web Sharing with custom domain name

    Hi, I am wondering if I can use a custom domain name with the built in web sharing. Instead of it going to http://10.0.0.2/ it will be http://www.mydomain.com/. Thanks in advance. Ryan

  • Problem with Entity PK Attributes & VO inputListOfValues

    Hello, im using Jdev 11.1.1.3.0 and have this issue. Use Case: 4 PK Entity Attributes that are used in a view object as Input List of Values. On a JSPx, there's a table where LOVs are located, The problem appears when i call createInsert method and s