Seetharaman Venkatasamy wrote:your *public T getData() * expect the generic return type T . but you have returned a string! so change the method return type as String[preferable approach] else cast the string to T and return as in *return (T)s*; <edit>added clarity</edit>
karthik swamy wrote:but can it wil work for integer type
Seetharaman Venkatasamy wrote: karthik swamy wrote:but can it wil work for integer type actually *return (T)s* this lead you in confusion. that is why I said first approach is preferable. Yes , it will work for an Integer type also
Seetharaman Venkatasamy wrote:
karthik swamy wrote:but generics is used for auto typecast then why we are typecasting like return (t)s