java - Subclasses as arguments to abstract method -


I have intangible class animals and flowers in my program animals eat flowers, but each animal only eat a certain type of flowers (Like Rhino eat only rose, turtle eat tulips).

Now my code looks like this:

Public intangible class animal (abstract boolean eating flower (flower f);} Public class Rhino provides animal {Boolean food Flower (flower f) {if ((for example (rose!) False return; return (f.eaten = true);}} Public squares provide turtle animals {Boolean eating flower (flower f) {if ( (For example, Tulip!) False return; return (f.eaten = true);}}

I apply this distinction to ins Tanceof where every animal eats only one type of flowers, I eat it turtle and Rhino's method signature for flavor (tulip t) and eaters (Rose R) respectively, but I do not think it is possible in Java.

Is using the example to implement it Is there a better way to do it?

The generic can use something like:

  public abstract class Animal & lt; T flower extension & gt; {Intangible zero-free flower (TF); } Public Square Rhino Animal & lt; Rose & gt; {Nilless flower (daily F) {}}  

Comments

Popular posts from this blog

apache - 504 Gateway Time-out The server didn't respond in time. How to fix it? -

c# - .net WebSocket: CloseOutputAsync vs CloseAsync -

c++ - How to properly scale qgroupbox title with stylesheet for high resolution display? -