Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
@manrock007 cup.getContents() returns generic type T which hopefully implements IFluid and IEdible.
You still don't know what the content is. -
You are assuming one of the two implemented interfaces has a getName() method. 🙂
-
@kwilliams I hope for the developer's sake that my assumption is correct.. Otherwise somebody's gonna get gently fucked with a chainsaw!
-
just take the type of T in the constructor TypeToken<T> and do typeToken.getType() to get the type
-
And i dont understand how this is polymorphism, isnt polymorphism when method behavior changes at run time based on the overriding etc?
-
@liveCoder the cup can be a container for items ranging from tea, coffee to pencils, chloroform.. Analogous to container classes that can hold integers, booleans or User defined classes..
-
@manrock007 but thats not polymorphism is it? the behavior i. e the class method logic doesnt change at runtime it just accepts/returns different types, this is called templating or generics nothing to do with polymorphism imo
-
@liveCoder I think you need to read it up in detail.. There's two types of polymorphism, runtime and compile time.. The cup represents runtime polymorphism.. That's because there's no way to determine what the cup will hold when the cup is manufactured.. It is only designed as an empty container that can hold different materials. Solid /liquid /hot /cold /viscous /even gases.. Hence run time polymorphism
-
@manrock007 I also thought that a polymorphism is just, for example, the changing behavior of + in sum and concatenation.
Polymorphism
undefined
cup of t
coffee?