java - Using super class as the type parameter in generic subtype -


why code piece give incompatible type error?

public class sample<t extends number> {     t dosomething() {         return new integer(0);     } } 

it gives compiler error because compiler, t extends string, string won't match t unless t string, can't , won't assume. purpose, compiler ignores fact string final class.

in case, using generic type parameter t useless. clearer , compile.

public class sample {     string dosomething() {         return "test";     } } 

Comments

Popular posts from this blog

user interface - How to replace the Python logo in a Tkinter-based Python GUI app? -

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -