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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T21:01:31+00:00 2026-06-01T21:01:31+00:00

This code seems to work fine class Rule<T> { public <T>Rule(T t) { }

  • 0

This code seems to work fine

class Rule<T>
{

    public <T>Rule(T t)
    {

    }
    public <T> void Foo(T t)
    {

    }
 }
  1. Does the method type parameter shadow the class type parameter?
  2. Also when you create an object does it use the type parameter of the class?

example

Rule<String> r = new Rule<String>();

Does this normally apply to the type parameter of the class, in the situation where they do not conflict? I mean when only the class has a type parameter, not the constructor, or does this look for a type parameter in the constructor? If they do conflict how does this change?

SEE DISCUSSION BELOW

if I have a function call

x = <Type Parameter>method(); // this is a syntax error even inside the function or class ; I must place a this before it, why is this, and does everything still hold true. Why don't I need to prefix anything for the constructor call. Shouldn't Oracle fix this.
  • 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-01T21:01:34+00:00Added an answer on June 1, 2026 at 9:01 pm

    All of your Ts are different, but you can only see it if you call your methods with the complete syntax:

    For example, this code is valid:

    new <Float>Rule<Integer>().<Character>Foo();
    

    Just to make this easier to explain, let’s assume your code is this:

    class Rule<A>
    {
    
        public <B>Rule()
        {
    
        }
        public <C> void Foo()
        {
    
        }
     }
    

    Then you can explicitly declare generic types like:

    new <B>Rule<A>().<C>Foo();
    

    If the types have the same name, the inner-most one will be chosen (the T on the method, not the class):

    With this code, taking parameters:

    class Rule<T>
    {
    
        public <T>Rule(T t)
        {
    
        }
        public <T> void Foo(T t)
        {
    
        }
    }
    

    Then this is valid:

    new <Float>Rule<Integer>(3.2f); 
    

    Note that T in the constructor is Float, not Integer.

    Another example:

    class Example<T> {
    
        public <T> void foo1() {
            // T here is the <T> declared on foo1
        }
    
        public void foo2() {
            // T here is the <T> declared on the class Example
        }
    }
    

    I found another question that deals with calling methods with explicit generic types without something before them. It seems like static imports and same-class method calls are the same. It seems like Java doesn’t let you start a line with <Type> for some reason.

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

Sidebar

Related Questions

Ok so i have the following code setup which seems to work fine: user
I've stress tested the code below and it seems to work fine - what
I have the following code class OverlayTask extends AsyncTask<Void, Void, Void> { @Override public
for some reason this code wont work, it doesn't seem to read the javascript.php
I have 2 questions on this My code always seems to hit a 401
this seems to be weird but it really happened. I have this code working
I have this code and can't figure out what seems to be the problem:
I have this code for splitting input list into its halves. It seems to
I have absolutely no idea why this is happening but the following code seems
I just can't see what's wrong with this code.. it seems to be the

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.