Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>What you can do in such a case is having a proxy handler that will redirect calls to existing methods of your abstract class.</p> <p>You of course will have to code it, however it's quite simple. For creating your Proxy, you'll have to give him an <code><a href="http://docs.oracle.com/javase/7/docs/api/java/lang/reflect/InvocationHandler.html" rel="nofollow noreferrer">InvocationHandler</a></code>. You'll then only have to check the method type in the <code><a href="http://docs.oracle.com/javase/7/docs/api/java/lang/reflect/InvocationHandler.html#invoke(java.lang.Object,%20java.lang.reflect.Method,%20java.lang.Object[])" rel="nofollow noreferrer">invoke(..)</a></code> method of your invocation handler. But beware : you'll have to check the method type against the underlying object associated to your handler, and not against the declared type of your abstract class.</p> <p>If I take as an example your dog class, your invocation handler's invoke method <strong>may</strong> look like this (with an existing associated dog subclass called .. well ... <code>dog</code>)</p> <pre><code>public void invoke(Object proxy, Method method, Object[] args) { if(!Modifier.isAbstract(method.getModifiers())) { method.invoke(dog, args); // with the correct exception handling } else { // what can we do with abstract methods ? } } </code></pre> <p>However, there is something that keep me wondering : I've talked about a <code>dog</code> object. But, as the Dog class is abstract, you can't create instances, so you have existing subclasses. Furthermore, as a rigorous inspection of Proxy source code reveals, you may discover (at Proxy.java:362) that it is not possible to create a Proxy for a Class object that does not represents an interface).</p> <p>So, apart from the <strong>reality</strong>, what you want to do is perfectly possible.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload