M
Martijn Mulder
From within an inner class I call a method in the enclosing
class with the same name but WITH A DIFFERENT SIGNATURE. The
compiler (jikes) complains:
Found 1 semantic error compiling "./Mouse.java":
25. mouseMoved(a.getX(),a.getY());
<--------------------------->
*** Error: The method "void mouseMoved(int a, int b);" contained in
the enclosing type "Mouse" is a perfect match for this method call.
However, it is not visible in this nested class because a method
with the same name in an intervening class is hiding it.**
Why is this? The name is the same but the signature is not.
A slight change in the name (houseMoved instead of mouseMoved)
makes it all work. What is the 'intervening class' jikes mouns
about?
//class Mouse
class Mouse extends javax.swing.JFrame
{
//constructor, add mouse motion listener as inner class
Mouse()
{
addMouseMotionListener
(
new javax.swing.event.MouseInputAdapter()
{
//mouseMoved
public void mouseMoved(java.awt.event.MouseEvent a)
{
System.out.println("MouseInputAdapter.mouseMoved");
mouseMoved(a.getX(),a.getY()); //not accepted
// houseMoved(a.getX(),a.getY()); //accepted alternative
}});
setDefaultCloseOperation(javax.swing.JFrame.EXIT_ON_CLOSE);
setSize(100,100);
setVisible(true);
}
//mouseMoved, method called from inner class. Rejected
void mouseMoved(int a,int b)
{
System.out.println("Mouse.mouseMoved");
}
//houseMoved, method called from inner class. Accepted
void houseMoved(int a,int b)
{
System.out.println("Mouse.houseMoved");
}
//main
public static void main(String[]a)
{
new Mouse();
}}
class with the same name but WITH A DIFFERENT SIGNATURE. The
compiler (jikes) complains:
Found 1 semantic error compiling "./Mouse.java":
25. mouseMoved(a.getX(),a.getY());
<--------------------------->
*** Error: The method "void mouseMoved(int a, int b);" contained in
the enclosing type "Mouse" is a perfect match for this method call.
However, it is not visible in this nested class because a method
with the same name in an intervening class is hiding it.**
Why is this? The name is the same but the signature is not.
A slight change in the name (houseMoved instead of mouseMoved)
makes it all work. What is the 'intervening class' jikes mouns
about?
//class Mouse
class Mouse extends javax.swing.JFrame
{
//constructor, add mouse motion listener as inner class
Mouse()
{
addMouseMotionListener
(
new javax.swing.event.MouseInputAdapter()
{
//mouseMoved
public void mouseMoved(java.awt.event.MouseEvent a)
{
System.out.println("MouseInputAdapter.mouseMoved");
mouseMoved(a.getX(),a.getY()); //not accepted
// houseMoved(a.getX(),a.getY()); //accepted alternative
}});
setDefaultCloseOperation(javax.swing.JFrame.EXIT_ON_CLOSE);
setSize(100,100);
setVisible(true);
}
//mouseMoved, method called from inner class. Rejected
void mouseMoved(int a,int b)
{
System.out.println("Mouse.mouseMoved");
}
//houseMoved, method called from inner class. Accepted
void houseMoved(int a,int b)
{
System.out.println("Mouse.houseMoved");
}
//main
public static void main(String[]a)
{
new Mouse();
}}