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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T10:14:00+00:00 2026-05-23T10:14:00+00:00

No static member can use a type parameter, but is it possible to call

  • 0

No static member can use a type parameter, but is it possible to call a static member using the generic type parameter? For example:-

abstract class Agent<A>{
    void callAgent();
    Agent(){
        A.add();                    
    }
}

Here add() is a static method.

There are some C# questions and answers on a similar topic but I’m not too sure how to go about it in Java.

  • 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-23T10:14:01+00:00Added an answer on May 23, 2026 at 10:14 am

    No you cannot do it if A is a generic type. (Bozho answered to fast 🙂 and probably thought A was concrete type.

    What will work is the following.

    abstract class Agent extends Blah<ConcreteA>{
        void callAgent();
        Agent() {
            ConcreteA.add();
        }
    }
    

    but it’s probably not what you want to do.

    After reading your comments it sounds like what you really want to do is:

    abstract class Agent<A extends SomeClassThatSupportsAdd> {
    
        void callAgent();
        protected abstract A createNew();
    
        Agent() {
            A a = createNew();
            A.add();
        }
    }
    

    Your subclasses will have to override createNew().

    If you still do not like that you can take a look at AspectJ which will allow you to do some constructor magic (see how spring does @Configurable) but that gets far trickier and complicates things.

    Another option is Scala. Java does not do inheritance on static methods so you can’t get parameterized modules (groups of functions in some languages this is called a functor … ocaml). However Scala supports a singleton “object” that does allow for parametric functional polymorphic inheritance.

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

Sidebar

Related Questions

Possible Duplicates: Get method name and type using lambda expression Can I use Expression<Func<T,
How can I access a public static member of a Java class from ColdFusion?
Inside of a static member function I need to get the type. class MyClass
1) Static class members can be used to separate data and behavior that is
I know I can get the public static members of a class by doing
Why can we have static final members but cant have static method in an
You can have different naming convention for class members, static objects, global objects, and
how to initialize a private static member of a class in java. trying the
I have a class which have a static member. As I understand, all static
I have structure defined in some header (D3DXVECTOR3) How can I declare: static member

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.