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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T02:04:02+00:00 2026-06-11T02:04:02+00:00

I created classes like below in the same package test . It was just

  • 0

I created classes like below in the same package test. It was just to test whether java really allows it. And it does but then it comes in to problems.

package test;

public class E {
}


package test;

public class T {
}


package test;

import test.E;
import test.T;

public class K<E, T> {

E e;
T t;

public K(E e, T t) {
    this.e = e;
    this.t = t;
}

public static void main(String[] args) {
    K k = new K<E, T>(new E(), new T());
}
}

Above code give multiple compilation problems

Multiple markers at this line
- Cannot make a static reference to the non-static type E
- Cannot make a static reference to the non-static type T
- Cannot make a static reference to the non-static type T
- Cannot make a static reference to the non-static type E
- K is a raw type. References to generic type K<E,T> should be 
 parameterized

It clearly shows compiler is confused between E and class E same for T.

So workaround is define it real types using package.

 K k = new K<test.E, test.T>(new test.E(), new test.T());

Now if there all these classes are in default package there is no way to solve this compilation issue.
So Question is should java allow declaration of such classes in default package?

  • 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-11T02:04:07+00:00Added an answer on June 11, 2026 at 2:04 am

    It clearly shows compiler is confused between E and class E same for T.

    I think you’ve got that wrong. I think that if you read the relevant parts of the JLS carefully (I’ll look them up later) you will find that they clearly state what E and T should resolve to in the various contexts. I would be very surprised if the compiler is getting the resolution wrong; i.e. not implementing the JLS.

    In reality, the confusion is in the mind of the person who wrote the code …

    The problem here is that the rules about what takes precedence over what are probably not what you (and typical programmers) expect. But they are like they are for a good reason.

    Normally this doesn’t matter, but if you ignore the normal Java naming conventions and use one-letter names for classes, then you might get burnt.

    So Question is should java allow declaration of such classes in default package?

    Alternatively, should “you” be ignoring the Java class naming conventions?

    Frankly, there are a lot of ways that a programmer can hurt themselves if they ignore the style guidelines / recommendations. But if you try to protect the programmer too much, you actually hurt him/her by making it impossible to implement stuff where you need to push the envelope. The best policy is (IMO) to not treat programmers as children. If they really want to juggle with sharp knives … let them.

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

Sidebar

Related Questions

I'm struggling with code that looks like the example below (but actually does something
Say I've got a domain model created from C# classes like this: public class
I have some shaped created using flex primitive classes like ellipse , rectangle, path
I'd like to use object database to persist some classes created in IronPython. The
I have 2 classes, X and Y. Both classes have same similar property like
I have 2 classes like below. public class Quest { public int ID{ get;set;
I have created the below function to bind to all the classes of type
I would like your guidance on how to create classes and their relationships (generalization,
Is it possible and how to create objects of such classes like NSString from
I'd like to create various sorting classes (QuickSort, MergeSort, BucketSort...etc). I have a common

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.