Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can't access a method that doesn't exist. All you've promised your Java compiler is that <code>oDataOne</code> and <code>oDataTwo</code> are <code>MyData</code> objects. Since the <code>MyData</code> class doesn't have the implementation-specific methods, you cannot ask Java to call those methods (since it doesn't think they exist).</p> <p>If you want to access those methods, you need to either cast the object to a class that actually has the right methods, or you can add abstract method stubs to your base class, which will tell Java that those methods actually exist.</p> <p>Type casting is simpler to write in the short term, but less clear, and you may run into more trouble down the road:</p> <pre><code>((DataTypeOne) oDataOne).getsName(); ((DataTypeTwo) oDataOne).getsSummary(); // Throws ClassCastException! </code></pre> <p>Adding abstract stubs is more robust, but may not make sense if not all concrete subclasses should implement all abstract methods:</p> <pre><code>public abstract class MyData { public abstract void setsName(String name); public abstract String getsName(); public abstract void setsSummary(String summary); public abstract String getsSummary(); } public class DataTypeOne extends MyData { public String getsName() { // implement } public void setsName(String name) { // implement } // Still have to implement these!!! public String getsSummary() { // raise an exception or something if appropriate } public void setsSummary(String summary) { // raise an exception or something if appropriate } } // Same for DataTypeTwo </code></pre>
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    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