1 2 Previous Next 24 Replies Latest reply: Jan 30, 2009 11:20 AM by 796440 Go to original post RSS
      • 15. Re: Custom serialization - could you do this?
        807588
        Tally*

        geogemc - Can't do it even though he says he can. Can't back up anything that comes out of his mouth.
        • 16. Re: Custom serialization - could you do this?
          807588
          Hi phdk

          You're new to the thread.

          See this post to see why you can ignore #11.

          http://forums.sun.com/thread.jspa?threadID=5363902
          • 17. Re: Custom serialization - could you do this?
            796440
            jwenting wrote:
            a schoolkid that fails to pay attention in class because he's undressing the girls sitting in front of him with his eyes, and spends his evenings watching porn online instead of doing his homework.
            Well, to be fair, it's not just schoolkids that do that. Er, um, or so I'm told.
            • 18. Re: Custom serialization - could you do this?
              800025
              Is this what you mean?
              import java.lang.reflect.Field;
              
              public final class DisplayUnderstanding {
              
                  public static abstract class AbstractData {
              
                   private int a = 0;
              
                   public AbstractData(int a) {
                       this.a = a;
                   }
              
                  }
              
                  public static class Data extends AbstractData {
              
                   private int b = 0;
              
                   public Data(int a, int b) {
                       super(a);
                       this.b = b;
                   }
              
                  }
              
                  public static void main(String[] args) {
                   Data data = new Data(5, 6);
                   showFields(data);
                   showValueOfA(data);
                   showValueOfB(data);
                   setValueOfA(data, 8);
                   setValueOfB(data, 10);
                   showValueOfB(data);
                   showValueOfA(data);
                  }
              
                  /**
                   * Will change the value of the field <code>a</code> in the instance
                   * <code>data</code> to <code>value</code>.
                   */
                  public static void setValueOfA(Data data, int value) {
                   try {
                       Field field = AbstractData.class.getDeclaredField("a");
                       field.setAccessible(true);
                       field.set(data, value);
                       field.setAccessible(false);
                   } catch (Throwable t) {
                       throw new RuntimeException(t);
                   }
                  }
              
                  /**
                   * Will change the value of the field <code>b</code> in the instance
                   * <code>data</code> to <code>value</code>.
                   */
                  public static void setValueOfB(Data data, int value) {
                   try {
                       Field field = Data.class.getDeclaredField("b");
                       field.setAccessible(true);
                       field.set(data, value);
                       field.setAccessible(false);
                   } catch (Throwable t) {
                       throw new RuntimeException(t);
                   }
                  }
              
                  public static void showFields(Data data) {
              
                   Class<?> clazz = null;
                   Field[] fields = null;
              
                   clazz = data.getClass();
                   while (clazz != null) {
                       fields = clazz.getDeclaredFields();
                       for (Field field : fields) {
                        System.out.println(field.getName() + ": " + field.getType());
                       }
                       clazz = clazz.getSuperclass();
                   }
              
                  }
              
                  /**
                   * Will write to <code>System.out</code> the value of the field
                   * <code>a</code> in the instance <code>data</code>.
                   * 
                   */
                  public static void showValueOfA(Data data) {
                   try {
                       Field field = AbstractData.class.getDeclaredField("a");
                       field.setAccessible(true);
                       System.out.println("Value of a: " + field.get(data));
                       field.setAccessible(false);
                   } catch (Throwable t) {
                       throw new RuntimeException(t);
                   }
                  }
              
                  public static void showValueOfB(Data data) {
                   try {
                       Field field = Data.class.getDeclaredField("b");
                       field.setAccessible(true);
                       System.out.println("Value of b: " + field.get(data));
                       field.setAccessible(false);
                   } catch (Throwable t) {
                       throw new RuntimeException(t);
                   }
                  }
              
              }
              Piet
              • 19. Re: Custom serialization - could you do this?
                jwenting
                jverd wrote:
                jwenting wrote:
                a schoolkid that fails to pay attention in class because he's undressing the girls sitting in front of him with his eyes, and spends his evenings watching porn online instead of doing his homework.
                Well, to be fair, it's not just schoolkids that do that. Er, um, or so I'm told.
                hmm. Schoolkid mentality survives past schoolkid physical age?
                • 20. Re: Custom serialization - could you do this?
                  807588
                  Piet, you are true gentleman. Thank you. I'll give it a go now.
                  • 21. Re: Custom serialization - could you do this?
                    799716
                    RobBaby wrote:
                    Hi phdk

                    You're new to the thread.

                    See this post to see why you can ignore #11.
                    If you do not like the tone - just ignore it or report abuse. There is no reason in starting a flamewar.
                    >
                    http://forums.sun.com/thread.jspa?threadID=5363902
                    Well, what did you get from cotton.m s reply about looking into OOS?
                    • 22. Re: Custom serialization - could you do this?
                      807588
                      RobBaby wrote:
                      Tally*

                      geogemc - Can't do it even though he says he can. Can't back up anything that comes out of his mouth.
                      Funny, I remember that he and many others have given solutions for your task (homework or not) multiple times in the past. Heck, I might even have already answered it myself in one form or another. A little searching usually goes a lot further than trying to start a flamewar with the regulars.
                      • 23. Re: Custom serialization - could you do this?
                        807588
                        RobBaby wrote:
                        Tally*

                        geogemc - Can't do it even though he says he can. Can't back up anything that comes out of his mouth.
                        Yep, keep trying that and eventually ego will get the better of me. um
                        • 24. Re: Custom serialization - could you do this?
                          796440
                          @OP: I answered in your other thread. Please knock of the "prove it" nonsense. Nobody here has anything to prove to you or to anybody else. If you have the experience you claim, then you know that the wang-measuring contest you're trying to start is just a really bad Hollywood stereotype.
                          1 2 Previous Next