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

  • SEARCH
  • Home
  • 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 6577387
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T15:37:44+00:00 2026-05-25T15:37:44+00:00

In my program, I deal with classes and primitive types. If the program finds

  • 0

In my program, I deal with classes and primitive types.
If the program finds a class, it simply does one of the following calls :

  • Class.forName(classname)
  • cc.toClass() where cc is an instance of CtClass

However, if it finds a primitive type, things get worse :

  • Class.forName is not usable, it cannot be used with primitive types.
  • cc.toClass() returns null

It’s possible to call the TYPE field from primitive types wrapper class but how can I do it with reflection ?

Here is my code :

CtClass cc;//Obtained from caller code
Class<?> classParam;
if (cc.isprimitive()) {
    classParam= ?? // How can I get TYPE field value with reflection ?
} else {
    String nomClasseParam = cc.getName();

    if (nomClasseParam.startsWith("java")) {
        classeParam = Class.forName(nomClasseParam);
    } else {
        classeParam = cc.toClass();
    }
 }

Javassist 3.12.0.GA

EDIT:
I have posted the solution I chose in the anwsers below.
Anyway, I ticked Tom’s answer.

  • 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-25T15:37:45+00:00Added an answer on May 25, 2026 at 3:37 pm

    It looks to me like you can cast cc to its subclass CtPrimitiveType.

    If you wanted a wrapper, you could then use the method getWrapperName to get the class name of the appropriate wrapper. You can use Class.forName as usual to turn that name into a Class object. However, i don’t think you do want a wrapper, so this doesn’t help.

    Instead, i think you want getDescriptor, followed by a laboriously handcoded switch statement:

    switch(descriptor) {
        case 'I': classParam = int.class; break;
        // etc
    }
    

    Something like that really should be in Javassist. But as far as i can see, it isn’t.

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

Sidebar

Related Questions

I'm unsure how to deal with the UserDetail class. Program; A virtual account hierarchy,
Here's the deal: I'm trying, as a learning experience, to convert a C program
What program can I use to decompile a class file? Will I actually get
Strange program hang, what does this mean in debug? After attaching windbg I found
Here's the deal. I've got a program that will load a given assembly, parse
How does the functional programming paradigm deal with shared resources that need to maintain
My question is how does one abstract a database connection from the model layer
Current project: To make a time program in C# with two classes Time and
I have a program where I deal with a lot of very small numbers
So I'm writing a program and part of it is to deal with an

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.