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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T11:51:05+00:00 2026-05-29T11:51:05+00:00

I try to create this class: public class Class1<T extends Class2<E>> { … public

  • 0

I try to create this class:

public class Class1<T extends Class2<E>> {
    ...
    public E someFunction(T param) {
        ...
    }
    ...
}

I saw topic [blog]: Java class with 2 generic parameters and in it topic suggest using this solution:

public class Class1<T extends Class2<E extends Class3>, E extends Class3> {
    ...
    public E someFunction(T param) {
        ...
    }
    ...
}

It is works, but in this case I should using 2 parameters without one:

Class1<Class21<Class31>, Class31> var = ...

In this solution I duplicate class ‘Class31’. Has this task have more simple solution, to using following code:

Class1<Class21<Class31>> var = ...

Update1:

What problem are you trying to solve?

For example, I have class for images.
Images can be single-channel (gray image) and multi-channel (3 channels for RGB, HSB and etc. or 4 channels or RGB and etc. + Alpha channel).
Also, image can save value RGB in byte 0..255 or in float (0.0, 1.0) and it is different type of images.
So, I want to create class for this images and construct it as:

MyImage<MyChannelType3<MyColorTypeInt>>   img1 = ...
MyImage<MyChannelType3<MyColorTypeFloat>> img2 = ...
MyImage<MyChannelType1<MyColorTypeFloat>> img3 = ...

and have access to colors in pixel as:

int Red     = img1.getPixel(x, y)[0];
float Green = img2.getPixel(x, y)[0];
float Gray  = img3.getPixel(x, y);

I think is more useful than:

MyImage<MyChannelType3<MyColorTypeInt>>   img1 = ...
int Red = img1.getPixel(x, y).getChannel(0).getValue();

If I will be firs return MyChannelType3, than MyColorTypeInt and then value or return Object and demand casting it to int, float, int[] or float[].

  • 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-29T11:51:08+00:00Added an answer on May 29, 2026 at 11:51 am

    This redundancy is unavoidable in Java.

    Explanation: In Java a type parameter is just what the name implies, a formal parameter for a type to be substituted with an actual type. What you require is more. You need T to be a parameter for a type constructor. Much like a classes’ constructor produces instances of the class, a type constructor produces types. List is a type constuctor which given the actual type String produces the type List<String>.

    Applying this knowledge to your problem, you would want T to be a type constructor which takes types E <: Class3 producing types T <: Class2<E> where <: is the subtype relation. This might be declared and used as follows.

    class Class1<T<X extends Class3> extends Class2<X>, E extends Class3> {
        public E someFunction(T<E> param) {
            ...
        }
    }
    
    Class1<Class21, Class31> var = ...
    

    Further reading on the subject can be found in Generics of a Higher Kind (pdf). Beyond that you can have a look at Scala which offers higher kinds.

    Edit based on update: A perhaps preferable solution might be to implement a PixelAccessor.

    public class PixelAccessor<C extends YourColor> {
        public static <C extends YourColor> get(Image<? extends ChannelType<? extends C>> image) {
            return new PixelAccessor<C>(image);
        }
    
        private final Image<? extends ChannelType<? extends C>> image;
    
        private PixelAccessor(Image<? extends ChannelType<? extends C>> image) {
            this.image = image;
        }
    
        public C getPixel(int x, int y) {
            // sadly this is unchecked, but "weak" type systems demand compromises
            @SuppressWarnings("unchecked")
            C color = (C) image.getPixel(x, y);
            return color;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I try to create a multi-threaded singleton pattern class. Header: class HL{ public: static
I have this code that's supposed to unzipp a file. public class dec extends
In Delphi, is normal do this: ob = TObject.create; try //code finally ob.free; end;
My code as follows: public class wall extends Activity { GridView webgridview; Button web;
I am getting the java.lang.SecurityException: Permission denied: file:////Videos/public/scripts/screenshot.jar when I try to use an
Here is the code: public class beautiful extends Activity { ImageView radar = (ImageView)
In my application I have a mapping like this @MappedSuperclass public abstract class Base
For manipulating a database I've created a class DBAdapter() that extends SQLiteHelper...this class has
I am trying to play a video through my application. public class VideoScreen extends
I try to create a new file inside a JSP and try to save

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.