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

  • Home
  • SEARCH
  • 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 6943739
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T13:11:45+00:00 2026-05-27T13:11:45+00:00

Why there are no any compilation errors in the second example but there is

  • 0

Why there are no any compilation errors in the second example but there is following compilation error in the first example?

SomeConcreateClass.java:1: ISomeBaseInterface cannot be inherited with different arguments: <java.lang.Object> and <>
public class SomeConcreateClass
       ^
1 error

The only difference – class SomeDerivedClass is not parameterized in the second example.

Example1:
Do I understand correctly that in this example

public class SomeConcreateClass
   extends SomeDerivedClass
   implements ISomeInterface
{}

class SomeDerivedClass<T> /* <-------*/
    extends SomeAbstractClass<Object>
    implements ISomeInterface
{}

abstract class SomeAbstractClass<T> 
   implements ISomeBaseInterface<T>
{}

interface ISomeInterface extends ISomeBaseInterface<Object> 
{}

interface ISomeBaseInterface<T>
{}

Example 2:

public class SomeConcreateClass
   extends SomeDerivedClass
   implements ISomeInterface
{}

class SomeDerivedClass /* <-------*/
    extends SomeAbstractClass<Object>
    implements ISomeInterface
{}

abstract class SomeAbstractClass<T> 
   implements ISomeBaseInterface<T>
{}

interface ISomeInterface extends ISomeBaseInterface<Object> 
{}

interface ISomeBaseInterface<T>
{}

UPDATE:
Do I understand correctly that in example below all tree starting from SomeDerivedClass will be used as raw type?
Information that first parameter for SomeBaseClass is List will be lost.
Is it correct?

import java.util.List;

public class SomeConcreateClass
   extends SomeDerivedClass
   implements ISomeInterface
{
    public static void main(String[] args) {
        SomeConcreateClass c = new SomeConcreateClass();
        List lst = c.getT(); //Type mismatch: cannot convert from Object to List
    }
}

class SomeDerivedClass<T>
   extends SomeBaseClass<List, T> /* <----- */
   implements ISomeInterface
{}

class SomeBaseClass<T, M>
   implements ISomeBaseInterface<T>
{
   public T getT(){return null;}
}

interface ISomeInterface extends ISomeBaseInterface<List> 
{}

interface ISomeBaseInterface<T>
{}
  • 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-27T13:11:45+00:00Added an answer on May 27, 2026 at 1:11 pm

    In short, use of raw type (i. e. use of generic type without type parameter) disables all generic-related stuff behind it.

    It’s usually demonstrated by the following example:

    class Foo<T> { public List<String> m() { ... } }
    
    String s1 = new Foo<Object>().m().get(0); // Compiles
    String s2 = new Foo().m().get(0); // Cannot cast Object to String
    

    You have the similar situation, but it’s related to inheritance rather than member access.

    Here is a relevant quote from JLS 4.8 Raw Types:

    The superclasses (respectively, superinterfaces) of a raw type are the erasures of the superclasses (superinterfaces) of any of its parameterized invocations.

    In your first example, SomeDerivedClass is generic, and SomeConcreteClass inherits it as a raw type. Thus, ISomeBaseInterface<Object> inherited through this branch of inheritance turns into its erasure ISomeBaseInterface<>, but ISomeInterface inherited directly still inherits ISomeBaseInterface<Object>. Since you cannot implement the same generic interface many times with different type parameters, compiler reports an error.

    In the second example, SomeDerivedClass is not generic, therefore there are no problems with raw types.

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

Sidebar

Related Questions

Is there any way to show compilation errors in colors on the terminal? I
Is there any way to access the <compilation /> tag in a web.config file?
Is there any efficiency difference in an explicit vs implicit inner join? For example:
The example program below compiles two in-memory assemblies. The first compilation works fine. The
Is there any possibility to make compiler continue when errors are encountered during the
Are there any conflicts with having any combination of Visual Studio 2003, 2005 and/or
Is there any free software tool or combination that allows me to identify the
Is there any way to improve code completion in notepad++? Currently it supports some
Is there any way to add my own completion to an (interactive) elisp function?
Is there any way to check whether a file is locked without using a

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.