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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T10:34:20+00:00 2026-06-09T10:34:20+00:00

I am wondering do we use generic method only if the method is static

  • 0

I am wondering do we use generic method only if the method is static ? for non-static you would define a generic class and you don’t necessary need it to be generic method. Is that correct ?

for example,

  public class Example<E>{

         //this is suffice with no compiler error
         public void doSomething(E [] arr){
                for(E item : arr){
                    System.out.println(item);
                }
         }

         //this wouldn't be wrong, but is it necessary ?
         public <E> doSomething(E [] arr){
                for(E item : arr){
                    System.out.println(item);
                }
         }
  }

whereas the compiler will force to add type parameter to make it a generic method if it’s static.

  public static <E> doSomething(E [] arr){


  }

I am not sure if i am correct or not.

  • 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-06-09T10:34:22+00:00Added an answer on June 9, 2026 at 10:34 am
    public class Example<E>{
    

    defines a generic type for instance’s methods and fields.

    public void <E> doSomething(E [] arr){
    

    This defines a second E which is different to the first and is likely to be confusing.

    Note: void is still needed 😉

    Static fields and methods do not use the generic types of the class.

    public static <F> doSomething(F [] arr) { }
    
    private static final List<E> list = new ArrayList<>(); // will not compile.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How would you suggest using AsEnumerable on a non-generic IQueryable ? I cannot use
I was wondering how to use the self:: and $this combined in a static
I would like to store data in Generic Dictionary with keys that match over
Someone told me that I need to use a delimiter in my trigger. I'm
I can create classes that use generics , however I was wondering if it
I wanted to create a generic interface with a method I could use to
I wondering whether use a webView to create a complex text area done with
Studying compilers course, I am left wondering why use registers at all. It is
I am wondering why my use of swprintf_s is generating the linker warning warning:
I am wondering how to use Model Binding in a scenario where I am

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.