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 958851
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T00:55:50+00:00 2026-05-16T00:55:50+00:00

Defining simple getters and setters is easy using Asm (and fortunately it is even

  • 0

Defining simple getters and setters is easy using Asm (and fortunately it is even explained in their FAQ). But one thing that is not mentioned, and for which I have been unable to find documentation, is how to implement these using generic type information.

I am actually able to determine generic type information itself quite easily (since code will take existing fields and/or methods and full generic type handling and resolution exists). I just need to generate generics version for types that have generic type included.

I hope this is something as easy as modifying signature Asm ClassWriter/MethodVisitor calls take, but some comments in documentation indicate it might not be that easy (as generics information is stored in bit different place than regular info).

EDIT: looks like entry point is “ClassWriter.visitField/Method(…., String signature) — note that it’s “description” that contains normal non-generic class information, but term “signature” (in JLS) specifically refers to generics-including type information.

  • 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-16T00:55:51+00:00Added an answer on May 16, 2026 at 12:55 am

    You can build the signature using ASM’s SignatureWriter class.

    For example, suppose you wish to write the signature for this method:

    public <K> void doSomething(K thing)
    

    You could use this code:

    SignatureWriter signature = new SignatureWriter();
    signature.visitFormalTypeParameter("K");
    
    // Ensure that <K> extends java.lang.Object
    {
        SignatureVisitor classBound = signature.visitClassBound();
        classBound.visitClassType(Type.getInternalName(Object.class));
        classBound.visitEnd();
    }
    
    // The parameter uses the <K> type variable
    signature.visitParameterType().visitTypeVariable("K");
    
    // The return type uses the void primitive ('V')
    signature.visitReturnType().visitBaseType('V');
    
    signature.visitEnd();
    
    String signatureString = signature.toString();
    

    Which is equivalent to:

    String signatureString = "<K:Ljava/lang/Object;>(TK;)V;"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Defining custom components in Facelets is easy and quick but there's one thing I
I can't figure out how to do such a simple thing like defining constants
This should be a simple one, but I can't figure out the problem. I
When defining simple DataMapper resource, it sets default storage engine to InnoDB, but I
Should be simple enough but might not be. When using action bar in Android
I have Developed a Bubble Chart in Asp.net using a simple sqldatsource by defining
Atleast defining my problem is simple... I have a Input control (Text) and a
What is a simple example of decorating a class by defining the decorator as
I am having trouble defining and automating my build process despite simple requirements: Every
I have a small program to demonstrate simple inheritance. I am defining a Dog

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.