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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T11:34:28+00:00 2026-05-13T11:34:28+00:00

I have classes abstract class A { //…. } class B extends A {

  • 0

I have classes

abstract class A {
    //....
}

class B extends A {
    //....
}

class C extends A {
    //....
}

Then I have

interface Maker<T extends A> {
    SomeClass make(T obj);
}

implementations for Maker class

class MakerForB implements Maker<B> { /*... */ }
class MakerForC implements Maker<C> { /*... */ }

and class Factory with one static method

class Factory {
    public static SomeClass makeSomeClass(A obj) {
        Maker maker = null;
        if(obj instanceof B) maker = new MakerForB();
        /* ... */
        return maker.make(obj);
    }
}

In that case I get warning that Maker is a raw type, when I declare Maker that way

Maker<?> maker = null;

I get exception (make is not applicable for the arguments A) on

return maker.make(obj);

What is the best way to get rid of these warnings without using

@SuppressWarnings("unchecked")
  • 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-13T11:34:29+00:00Added an answer on May 13, 2026 at 11:34 am

    Get rid of all generics on the Maker – you don’t need it:

    interface Maker {
        SomeClass make(A obj);
    }
    
    class MakerForB implements Maker {
        SomeClass make(A obj);
    }
    

    Or if you still want to use it, go with an unsafe cast or with the SuppressWarnings.

    To understand why you get an error if your try defining:

    Maker<? extends A> maker = null;
    

    Imagine the case when you (by accident) get maker = new MakerForC(), and try applying it to B.

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

Sidebar

Related Questions

I have this classes interface UserInterface Then abstract class user implements UserInterface Then i
I have the following classes: abstract class DTO{ } class SubscriptionDTO extends DTO {
I have just implemented some classes: public abstract class Job<T extends ViewerUnion>{ [...] }
I have the following classes: public abstract class ClassWithHelper<T extends HelperInterface> { Class<T> helperClass;
I have 3 simple classes: public abstract class Container implements WritableComparable<Container> {} //empty public
I have a singleton class that implements two other abstract classes. My monkey::getMonkey fails
Basically, I have 3 classes class abstract A{} protected aMethod(){} class abstract B extends
In my Android application, i have the following classes: public abstract class A implements
Lets say i have the following c# classes: abstract class a { protected abstract
Let's say I have some classes like this: abstract class View(val writer: XMLStreamWriter) {

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.