views:

741

answers:

2

Hello colleagues, Small preamble. I was good java developer on 1.4 jdk. After it I have switched to another platforms, but here I come with problem so question is strongly about jdk 1.6 (or higher :) ). I have 3 coupled class, the nature of coupling concerned with native methods. Bellow is example of this 3 class

public interface A
{
     public void method();
}
final class AOperations
{
     static native method(. . .);
}
public class AImpl implements A
{
    @Override
    public void method(){ 
        AOperations.method( . . . );
    }
}

So there is interface A, that is implemented in native way by AOperations, and AImpl just delegates method call to native methods. These relations are auto-generated. Everything ok, but I have stand before problem. Sometime interface like A need expose iterator capability. I can affect interface, but cannot change implementation (AImpl).

Saying in C# I could be able resolve problem by simple partial: (C# sample)

partial class AImpl{
 ... //here comes auto generated code
} 

partial class AImpl{
 ... //here comes MY implementation of 
 ... //Iterator 
} 

So, has java analogue of partial or something like.

EDITED: According to comment by @pgras I need some clarification. AImpl is not in vacuum, there is some factory (native implemented) that returns instance of AImpl, that is why creation of inheritance from AImpl, is not applicable.

EDITED 2: May be it doesn't relate, but how it is done by JUnit 4:

public class SomeTest {
 ...
 //there is no direct inheritance from Assert, but I can use follow:
 assertTrue(1==1); //HOW DOES it works??
A: 

You could extend A (say interface B extends A) and extend AImpl and implement B (class BImpl extends AImpl implements B)...

pgras
@pgras thanks, but "no". I have described in **EDITED** why it is not applicable
Dewfy
+2  A: 

Java does not have support for partials or open classes. Other JVM languages do, but not Java. In your example, the simplest thing may unfortunately be to use delegation. You can have your AImpl take another object that fulfills an interface to these extension methods. The generated AImpl would then have generated methods such as iterator methods that it could delegate to the user created object you pass in.

Russell Leggett
+1: This is how the `Thread(Runnable runnable)` constructor works.
R. Bemrose
@Russell Leggett, ok may be it doesn't relates to my main question, but how can work syntax from my **EDITED 2**
Dewfy
As Chris Smith said, thats a static method, using a static import to look more local.
Russell Leggett