groovy

Two interfaces with the same method

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Won't Fix
  • Affects Version/s: None
  • Fix Version/s: 1.5.5
  • Component/s: None
  • Labels:
    None
  • Number of attachments :
    0

Description

The code generates an error message

interface B {
def x()
}

interface C {
def x()
}

class A implements B, C{

def x(){ return 33 }
}

The error:

Exception thrown: java.lang.InstantiationException: B

java.lang.InstantiationException: B

But it is a possible situation in java.

Issue Links

Activity

Hide
Paul King added a comment -

This works fine for me on the comand-line with HEAD. How are you running your code?

Show
Paul King added a comment - This works fine for me on the comand-line with HEAD. How are you running your code?
Hide
ccadete added a comment -

I am using the Groovy 1.5.4, with the GroovyConsole

Show
ccadete added a comment - I am using the Groovy 1.5.4, with the GroovyConsole
Hide
Paul King added a comment -

I think we need a little more info. With this:

interface B { def x() }

interface C { def x() }

class A implements B, C {
    def x(){ return 33 }
}

new A().x()

I get in GroovyConsole on 1.5.4:

Result: 33
Show
Paul King added a comment - I think we need a little more info. With this:
interface B { def x() }

interface C { def x() }

class A implements B, C {
    def x(){ return 33 }
}

new A().x()
I get in GroovyConsole on 1.5.4:
Result: 33
Hide
ccadete added a comment -

The code is only this:

interface B { def x() }

interface C { def x() }

class A implements B, C{

def x(){ return 33 }
}

I am not doing nothing more, just declare the interfaces and the single class.

If I put at the end "new A().x()", it works fine.

What happens is that Groovy tries to instantiate the first class to find a "main" method to execute, but since it is an interface, it gives the InstantiationException, if you move the class declaration to the top you see that groovy cannot find the main method and that is the same that it tries to do with the interface.

Show
ccadete added a comment - The code is only this: interface B { def x() } interface C { def x() } class A implements B, C{ def x(){ return 33 } } I am not doing nothing more, just declare the interfaces and the single class. If I put at the end "new A().x()", it works fine. What happens is that Groovy tries to instantiate the first class to find a "main" method to execute, but since it is an interface, it gives the InstantiationException, if you move the class declaration to the top you see that groovy cannot find the main method and that is the same that it tries to do with the interface.
Hide
Paul King added a comment -

It does indicate at least an error message we can improve. What we you expecting to happen?

Show
Paul King added a comment - It does indicate at least an error message we can improve. What we you expecting to happen?
Hide
ccadete added a comment -

The code:

<code>
interface A { def x() }
</code>
returns the same error

Since the code have only declarations, I think that a simple message

<code>
Successfully loaded
<code>

indicates that the script has no sintax errors

Show
ccadete added a comment - The code: <code> interface A { def x() } </code> returns the same error Since the code have only declarations, I think that a simple message <code> Successfully loaded <code> indicates that the script has no sintax errors
Hide
blackdrag blackdrag added a comment -

I think the relation to GROOVY-1328 is a bit misleading here. The code above is given to either groovysh or groovyConsole and does not have a file name. As a result the compiler has no way to know for sure which class you intended to return. I think in this case returning the first class is as good as returning the last class and thus the current behaviour is good enough. of course you could argue that selecting a valid class over an invalid class would be better, but I disagree. I think in this case it is more important to have something you can count on than something that probably works.

Show
blackdrag blackdrag added a comment - I think the relation to GROOVY-1328 is a bit misleading here. The code above is given to either groovysh or groovyConsole and does not have a file name. As a result the compiler has no way to know for sure which class you intended to return. I think in this case returning the first class is as good as returning the last class and thus the current behaviour is good enough. of course you could argue that selecting a valid class over an invalid class would be better, but I disagree. I think in this case it is more important to have something you can count on than something that probably works.

People

Vote (0)
Watch (1)

Dates

  • Created:
    Updated:
    Resolved: