user1178168
user1178168

Reputation: 23

Type Error in Java 7

I have a dialog box class that extends JDialog. One method in this class is this:

public char getType()
{
return ((String)fileTypeCombo.getSelectedItem()).charAt(0);
}

where fileTypeCombo is this:

JComboBox fileTypeCombo = new JComboBox(
            new String[] { "Local", "Shared", "Remote" } );

I am getting the following error when I attempt to compile using Java 7:

[javac] /home/satin/decodes-8.0/lrgs/gui/NetlistDialog.java:112: error: getType() in NetlistDialog cannot override getType() in Window
[javac]     public char getType()
[javac]                 ^
[javac]   return type char is not compatible with Type

It compiles fine with Java 6.

Regards.

Upvotes: 2

Views: 1135

Answers (1)

Nick Garvey
Nick Garvey

Reputation: 3000

It is because of a method added to the Window class in Java 7.

The super class, Window, has public Window.Type getType() for the method signature in Java 7. You are attempting to override that method, but are returning a char instead of a Window.Type object, so a compilation error is occurring.

In Java 6 that method doesn't exist, so you don't get any errors.

Upvotes: 3

Related Questions