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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T18:21:19+00:00 2026-06-07T18:21:19+00:00

I have a class with the following definition: public abstract class A<T> implements Iterator<B>

  • 0

I have a class with the following definition:

public abstract class A<T> implements Iterator<B> {}

The following call to next() will return an Object rather than a B:

A a = new SomethingThatExtendsA();
B b = a.next();

I’ve searched for quite awhile and haven’t been able to figure out why this next() call fails to compile. Is anyone able to describe this behavior for me?

Edited original to be templated, as this seems to matter.

Edit for additional clarification: This is a compile-time issue, not a runtime issue. The implementation of SomethingThatExtendsA(); should be irrelevant in this case at compile-time.

  • 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-07T18:21:21+00:00Added an answer on June 7, 2026 at 6:21 pm

    So we have this code:

    public abstract class A<T> implements Iterator<B> {}
    [...]
    A a = new SomethingThatExtendsA();
    a.next();
    

    A is a generic type, but you have defined a with a raw type. Ignore the right hand side of the =, we are only interested in the static type:

    A/*<Something>*/ a = ...;
    

    The compiler should give you warnings here. (At least relatively recent versions of javac will do – rawtypes warning in Oracle javac.) Take notice of your compiler’s warnings. (Wasn’t it nice when javac didn’t give warnings?)

    So now we are in a situation that a has a type that is both raw and is a Iterator<B>. This is a really confusing situation with just mind-blowingly difficult implications. We shouldn’t even be doing this – we should be avoiding mixing generic and raw types. So the Java Language Specification takes the simple way out and discards the partial generic type information.

    So, don’t mix raw and generic types. Just use all generics and you should be fine.

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

Sidebar

Related Questions

I have the following abstract classes: public abstract class AbSuperClass1<K,S> { //class definition }
I have the following class definition: public interface IItem{} public class FirstObject<T, U> :
I have the following property definition: public static class Extensions { public static readonly
I have a question about .net generics. Consider the following code: public abstract class
I have the following DTO definition:- [DataContract] public class AddProductDTO { [DataMember] public string
Let's say I have the following class definition : List<SomeClass>... public class SomeClass {
I have the following base abstract class defined as: public abstract class BaseObject<T> :
I have the following class definition: class IRenderable { public: virtual void Render( wxBitmap
I have the following class definitions public abstract class AbstractClass { [Key] public string
I have this class definition: public abstract class AbstractListViewModel<T> : AbstractWorkspaceViewModel So I have

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.