Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing inheritance to alter a superclass's interface
    primarykey
    data
    text
    <p>I come from a web-development background. I've been playing around with a bit of Java recently and have come across the following issue that seems to stem from the strict interfaces and data-typing which are more part of Java than they are of PHP.</p> <p>I am using an existing physics engine (<a href="http://www.cokeandcode.com/phys2d/" rel="nofollow">Phys2D</a>) to develop a game of sorts. This physics engine has <code>Body</code> objects managed by a <code>World</code>, and have various forces applied to them as the world is stepped. It is important for the AI in the game that the bodies have colours (so that they can be sensed), but this is not supported by the physics engine, so I've created a subclass, and extended the <code>Body</code> class to include this - <a href="http://pastebin.com/1nLYWg3w" rel="nofollow">http://pastebin.com/1nLYWg3w</a>. Now when I create these <code>Body</code> instances, I can get them back from the <code>World</code> and get their colours.</p> <p>However, Netbeans is saying that it</p> <pre><code>cannot find symbol symbol: method getColour() location: class net.phys2d.raw.Body </code></pre> <p>because the <code>Body</code> objects returned by the physics engine interface do not contain this method. I know that, at runtime, <em>all</em> the <code>Body</code> objects that are passed to the <code>World</code> will actually be objects of <code>ColouredBody</code> type, and so will have this method defined in their interfaces.</p> <p>How can I attach colours to the <code>Body</code> objects and not produce scary underscores and warnings? I understand that I can alter Phys2D itself but, potential licensing restrictions aside (the licence says that you <em>can</em> do this with Phys2D), I am told that this is bad practice.</p>
    singulars
    1. This table or related slice is empty.
    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.
 

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