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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T15:29:00+00:00 2026-06-12T15:29:00+00:00

Hey there I have just started Java for a course I will be taking

  • 0

Hey there I have just started Java for a course I will be taking soon (yeah I’m a nerd, I study before I have start the class). I wanted to cram a few concepts together to learn how everything works together in Java.

Now, what I wanted to try to do is a simple Shape (Forme in french) class which has a least 1-2 classes inheriting from it and make a few instances inside a collections object. I also wanted to make those classes generics to try that out as well. That is the part I’m having trouble with.

I’m very used to C++ so that may be where the confusion lies, but it seems that I can’t use generics so that, for example, I can specify that dimensions will be in, say, Integer or Double or Float or whatever. Is it possible ?

The GetArea() method below can’t compile because of base and hauteur.

package testconcepts;

import java.util.*;
import java.lang.*;

abstract class Forme <T extends Number> {
    protected String nom_forme;

    String NomForme() { return nom_forme; }

    abstract Double GetArea();
}

class Triangle <T extends Number> extends Forme {
    protected T base, hauteur;

    Triangle() { 
        this.nom_forme = "TRIANGLE"; 
    }

    @Override
    Double GetArea() { return base * hauteur / 2; }

    T GetBase() { return base; }
    T GetHauteur() { return hauteur; }
    void SetBase(T base) { this.base = base; }
    void SetHauteur(T hauteur) { this.hauteur = hauteur; }
}

public class TestConceptsJava {
    public static void main(String[] args) {
        ArrayList list = new ArrayList();
        list.add(new Triangle<Double>());
    }
}

Notice that I also cannot make assignments to 0 in the constructor because of type issues.

Also, I know there are very similar topics, but I haven’t found a solution to my problem yet in those other questions.

TLDR How can I make work generics with primitive type wrappers (Double, Integer..) ?

  • 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-12T15:29:01+00:00Added an answer on June 12, 2026 at 3:29 pm

    In GetArea(), you’re calling the * operator on two classes. How much sense would it make to say something like:

    Object o1 = //whatever;
    Object o2 = //whatever;
    
    return o1 * o2;
    

    Not much right? You can’t multiply two classes. What you actually want to do is multiply the underlying value of those wrapper classes (which is not done implicitly for you in Java). Rewriting GetArea() like this should solve your problem:

    Double GetArea() { return base.doubleValue() * hauteur.doubleValue() / 2; }
    

    Note that you’ll also have to use the underlying value everywhere else that you care about it in that class.

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

Sidebar

Related Questions

Hey just a quick question for any experts out there. I have a site
Hey, say I have a url just being passed through my php is there
hey there, just practising and I had a question. I have a program (source
hey there i wonder if any of you have come across a similar issue?
hey there, i have a div that expands when the page is loaded, now
Hey guys, one more quick question for any experts out there. I have a
Hey there. I'm trying to write a small program that will read the four
Hey gang. I have just written a client and server in C++ using sys/socket.
If I have 'export BLA=hey there' in .profile in my home directory, how can
Hey guys I have a system where there is one form for each friend

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.