Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7090225
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T08:01:20+00:00 2026-05-28T08:01:20+00:00

Hello I’m doing some tests using reflection… so far I’ve got this: public class

  • 0

Hello I’m doing some tests using reflection…
so far I’ve got this:

public class MyConveter implements Converter {
private Class<?> myClass;

public MyConveter(Class<?> myClass) {
    this.myClass = myClass;
}

@Override
public boolean canConvert(Class clazz) {
    return clazz.equals(myClass);
}

@Override
public void marshal(Object arg0, HierarchicalStreamWriter arg1, MarshallingContext arg2) {
    // TODO Auto-generated method stub
}

@Override
public Object unmarshal(HierarchicalStreamReader arg0, UnmarshallingContext arg1) {
    try {
        Object obj = myClass.newInstance();
        Field daoField = myClass.getDeclaredField("id");
        daoField.setAccessible(true);
        daoField.set(obj, Integer.valueOf(5));
        Field daoField2 = myClass.getDeclaredField("value");
        daoField2.setAccessible(true);
        daoField2.set(obj, "proj name");
        return obj;
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } 

    return null;
}

}

But I don’t like the outcome is there a way of changing this to:

public class MyConveter<T> implements Converter;

thus removing the constructor?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T08:01:21+00:00Added an answer on May 28, 2026 at 8:01 am

    You can declare your class with a type parameter all you want; you do, however, need an instance of the class you are trying to convert (because it is used in the unmarshal method). All type information from generics is removed after compiling the class so the runtime has no way of knowing what class to create a new instance for.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello can anybody solve this please I'm creating the object in the action class
Hello i've got this problem with an ajax call in my (newbie) Drupal site.
Hello I am working with a simulator that uses rcS scripts to boot, this
Hello Guys I am trying to figure out why i am gettings this error
Hello , I am using arshaw fullcalendar v1.5.2 (only month view ) for property
Hello I am using jQuery UI Accodions By default, the first accordion is shown
Hello I call static PageMethod from JS. PageMethod send some information to emails. When
Hello I'm making RSS reader and I'm using DOM. Now I stuck, trying to
Hello At my form I create TFrame at runtime. At this frame I create
Hello i been trying to get a tokenizer to work using the boost library

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.