71
Comments
  • 0
    @Kushtrim cup.getContents()
  • 0
    Bullshit they stole my design!
  • 1
    @manrock007 cup.getContents() returns generic type T which hopefully implements IFluid and IEdible.
    You still don't know what the content is.
  • 0
    @kwilliams Jesus

    cup.getContents().getName()
  • 0
    You are assuming one of the two implemented interfaces has a getName() method. 🙂
  • 1
    @kwilliams I hope for the developer's sake that my assumption is correct.. Otherwise somebody's gonna get gently fucked with a chainsaw!
  • 0
    just take the type of T in the constructor TypeToken<T> and do typeToken.getType() to get the type
  • 1
    And i dont understand how this is polymorphism, isnt polymorphism when method behavior changes at run time based on the overriding etc?
  • 0
    @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..
  • 0
    lol c# : cup.getType()
  • 1
    @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
  • 1
    @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
  • 0
    @manrock007 I also thought that a polymorphism is just, for example, the changing behavior of + in sum and concatenation.
Add Comment