Solved

A templated rectangle

Posted on 2007-11-29
3
252 Views
Last Modified: 2010-03-30
Hi,
I have a rectangle class like:

public class MyRectangle
{
     int l, r, t, b;
}

because using the built in java one has doubles for the members instead of int and its really annoying to use with graphics drawing. How can I update it to just 'template' the type, something like:

public class MyRect<int>
{
     int l, r, t, b;
}
public class MyRect<double>
{
    double l, r, t, b;
}

etc?

Thanks
0
Comment
Question by:DJ_AM_Juicebox
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 14

Accepted Solution

by:
CPColin earned 500 total points
ID: 20375343
Which built-in Java class? The java.awt.Rectangle class uses ints.
0
 

Author Comment

by:DJ_AM_Juicebox
ID: 20375963
ah ok i was importing some other one using double as the type, this should be fine,

Thanks
0
 
LVL 23

Expert Comment

by:Ajay-Singh
ID: 20376674
This should work,
 
 
public class MyRectangle<T> {
  T l, r, t, b;
}
0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

718 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question