Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Error in getSize() getter - creating a size property that is an int array of height and width

Posted on 2007-03-27
5
Medium Priority
?
334 Views
Last Modified: 2010-03-31
Experts:

I'm trying to create a size property that is an int array of height and width:

      private int [] size = new int [2];

      public int [] getSize() {  // getSize() is underlined in red "here is my error"
            size[0] = height;
            size[1] = width;
            return size;
      }

      public void setSize(int h, int w) {
            height = h;
            width = w;
      }

When I hover the cursor over the getSize() it pops up the following message:  
The return type is incompatible with Component.getSize()

I've gone through all of my code looking for incompatibilities and I can't find any.  So, I'm beginning to think there is something wrong with my syntax.

Any ideas?
Thanks,
Patricia
0
Comment
Question by:pdlarue
[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
5 Comments
 
LVL 86

Assisted Solution

by:CEHJ
CEHJ earned 160 total points
ID: 18801764
return a type of java.awt.Dimension
0
 
LVL 86

Assisted Solution

by:CEHJ
CEHJ earned 160 total points
ID: 18801783
public Dimension getSize() {
      return new Dimension(width, height);
}
0
 
LVL 14

Assisted Solution

by:CPColin
CPColin earned 80 total points
ID: 18801786
Or, change your getSize method name. It is conflicting with the getSize method in Component, and you can't have a method with the same name and parameters but a different return type.
0
 
LVL 10

Accepted Solution

by:
ADSLMark earned 160 total points
ID: 18801820
Explanation:

You are trying to override a method from a superclass with the name: "getSize". Since this method returns a Dimension, you cannot define your own method "getSize" with the same type of parameters but a different return type.
Imagine the situation where you have:

int[] getSize(int width, int height);

and

Dimension getSize(int width, int height);

Now if i were to call getSize(800,600); which method should i choose? Java is not smart enough to know this, so it doesnt allow you to have these two functions simultaneous. Simple solutions are returning the correct type or changing the method name a bit, like getMySize(..).

Good luck,
Mark
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 18801964
:-)
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Suggested Courses

636 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