Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Kopie eines Objekts

Empfohlene Antworten

Veröffentlicht

Hallo zusammen,

Ich habe folgende Methode


    /*

     *  Adds an Action within all FollowActions specified in Vector 'folgeActions'

     *  inpXS is needed for Validation

     */

    public void add(LgSWKMA inpKMA, Vector folgeActions, EQXS inpXS) throws Exception

    {

        LgSWKMJ tmpKMJ = new LgSWKMJ();

        Vector tmpKMJVector = new Vector();


        if(!inited) {

            init();

        }


        hashKMA.put(inpKMA.getKey().getKeyAsString(),inpKMA);


[COLOR=green]        inpXS.setFLDandPARandEW("FIR","",inpKMA.getFIR());

        tmpKMJ.validateSetFIR(inpXS,false);

        inpXS.setFLDandPARandEW("VSAS","",inpKMA.getVSAS());

        tmpKMJ.validateSetVSAS(inpXS,false);

        inpXS.setFLDandPARandEW("KOLL","",inpKMA.getKOLL());

        tmpKMJ.validateSetKOLL(inpXS,false);

        inpXS.setFLDandPARandEW("MSTN","",inpKMA.getMSTN());

        tmpKMJ.validateSetMSTN(inpXS,false);

        inpXS.setFLDandPARandEW("MSTF","",inpKMA.getMSTF());

        tmpKMJ.validateSetMSTF(inpXS,false);

        inpXS.setFLDandPARandEW("MLST","",inpKMA.getMLST());

        tmpKMJ.validateSetMLST(inpXS,false);

        inpXS.setFLDandPARandEW("MBAK","",inpKMA.getMBAK());

        tmpKMJ.validateSetMBAK(inpXS,false);[/COLOR] 


[COLOR=red]        for(int i=0;i<folgeActions.size();i++) {


            inpXS.setFLDandPARandEW("MBFK","",(String) folgeActions.elementAt(i));

            tmpKMJ.validateSetMBFK(inpXS,true);

            System.out.println(tmpKMJ.getKey().getKeyAsString());

            tmpKMJVector.add(tmpKMJ);

        }[/COLOR]

        hashKMJ.put(hashKMA.get(inpKMA.getKey().getKeyAsString()),tmpKMJVector);

        System.out.println(hashKMJ);

        saved = false;

    }

Dadurch, dass ich immer das gleiche Objekt in der for-Schleife reinschiebe

Hab ich nach der Schleife in tmpKMJVector immer zig gleiche Objekte.

Ich müsste also in der Schleife das tmpKMJ-Objekt kopieren, da ich die

Validierung der Felder, die eh immer gleich sind, nicht unnötig oft machen will.

Meine Frage - Wie bekomme ich eine Kopie des tmpKMJ-Objektes?

Auf clone() Hab ich iregndwie keinen Zugriff, da es protected ist.

Du müsstest in der Klasse "LgSWKMJ" (oder welche du auch immer klonen willst) das Interface "Cloneable" implementieren. Dann musst du die clone-Methode in dieser überschreiben und schon kannst du eigentlich das Objekt klonen.

ABER VORSICHT!

Es ist wirklich nicht einfach und sinnvoll ein Objekt zu klonen.

Ich hatte mir daran schon mal die Zähne ausgebissen und im Endeffekt ne andere Möglichkeit gefunden.

Peet

  • Autor

Ich hab es jetzt so gemacht, daß ich mir vor der Schleife ein Objekt mache,

welches die Werte prüft.

In der Schleife erzeuge ich dann ein neues Objekt, welches einfach die geprüften Werte des ersten Objektes ohne nochmalige Prüfung aufnimmt!

Ich denke, daß das das einfachste war!

Trotzdem vielen Dank für Deine Hilfe

mfg

Archiv

Dieses Thema wurde archiviert und kann nicht mehr beantwortet werden.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.