XStream
  1. XStream
  2. XSTR-31

ReflectionProvider that handles non-default constructors for IBM JDK

    Details

    • Type: New Feature New Feature
    • Status: Closed Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 0.1
    • Fix Version/s: 1.2
    • Component/s: Compatibility
    • Labels:
      None

      Description

      Tip from Håkan Råberg at http://jroller.com/page/cv/20040310#wicked_reflection_tip:

      It's done like this in the IBM JDK:
      From the IBM ObjectInputStream.java:

      /* Allocate a new object for the specified class

      • Native since newInstance may not be able to find a zero arg constructor.
        */
        private static native Object allocateNewObject(Class aclass, Class initclass) throws InstantiationException, IllegalAccessException;

      Example how to use it to create an Object without default ctor:

      Method method = ObjectInputStream.class.getDeclaredMethod("allocateNewObject", new Class[]

      {Class.class, Class.class}

      );
      method.setAccessible(true);
      Locale l= (Locale) method.invoke(null, new Object[]

      {Locale.class, Object.class}

      );

        People

        • Assignee:
          Joe Walnes
          Reporter:
          Joe Walnes
        • Votes:
          0 Vote for this issue
          Watchers:
          0 Start watching this issue

          Dates

          • Created:
            Updated:
            Resolved: