Solved

A templated rectangle

Posted on 2007-11-29
3
249 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
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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
backtracking recursion  code 19 58
map related example 6 48
Groovy problem when using SOAPUI : DispatchException occurred 7 44
servlet example 11 40
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…

770 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