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

css - I want to align grid in center -

Contact Form PHP Email Script -

python - SWIG function not printing output -