Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Call A Method From Within Inner Class

Reply
Thread Tools

Call A Method From Within Inner Class

 
 
Martijn Mulder
Guest
Posts: n/a
 
      07-01-2005
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_O N_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();
}}


 
Reply With Quote
 
 
 
 
Daniel Dyer
Guest
Posts: n/a
 
      07-01-2005
On Fri, 01 Jul 2005 16:49:43 +0100, Martijn Mulder <i@m> wrote:

> 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?
>


Try javac, see if you get a less cryptic message. Then try the following:

Mouse.this.mouseMoved(a.getX(),a.getY());

Dan.

--
Daniel Dyer
http://www.dandyer.co.uk
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
failing to instantiate an inner class because of order of inner classes Pyenos Python 2 12-27-2006 11:19 PM
can call a method, but not a method within a user-defined class aidy Ruby 5 06-04-2006 08:10 PM
Nested Class, Member Class, Inner Class, Local Class, Anonymous Class E11 Java 1 10-12-2005 03:34 PM
inner class, explicit outer class method call Yamin Java 4 10-24-2004 06:17 AM
Help with a utility class and having a method call another method from within Ian Python 2 09-06-2003 03:35 PM



Advertisments