java - The type parameter T is hiding the type T -
my question is: why, if use linearlayout, instead of object
, "result" of asynctask
(tablewithinexplisttask<params, progress, linearlayout>
) , eclipse give me many errors cannot instantiate type linearlayout?
seems me doesn't recognise linearlayout
anymore in createformattedcell()
, can't undertstand why.
in asynctask
declaration linearlayout
has yellow underline , eclipse says: the type parameter linearlayout hiding type linearlayout.
please can explain me?
here code of class:
import android.content.context; import android.graphics.color; import android.graphics.typeface; import android.os.asynctask; import android.view.view; import android.widget.linearlayout; import android.widget.textview; public class tablewithinexplisttask<params, progress, linearlayout> extends asynctask<params, progress, linearlayout> { private final int table_border = 1; private final int table_text_padding = 10; private context context = null; private string str = null; private boolean tableheader = false; private linearlayout column = null; public tablewithinexplisttask(context context, string str, boolean tableheader, linearlayout column) { this.context = context; this.str = str; this.tableheader = tableheader; this.column = column; } @override protected linearlayout doinbackground(params... arg0) { return this.createformattedcell(this.tableheader, this.str); } @override protected void onpostexecute(linearlayout result) { this.column.addview(result); } private linearlayout createformattedcell(boolean tabheader, string str) { // layout che circonda le textview necessario per disegnare il bordo // delle celle linearlayout container = new linearlayout(this.context); container.setpadding(table_border, table_border, 0, 0); container.setbackgroundcolor(color.black); textview textview = new textview(this.context); textview.setpadding(table_text_padding, table_text_padding, table_text_padding, table_text_padding); textview.setbackgroundcolor(color.white); linearlayout.layoutparams params = new linearlayout.layoutparams(linearlayout.layoutparams.match_parent, linearlayout.layoutparams.match_parent); textview.setlayoutparams(params); if (tabheader) { textview.settypeface(typeface.default_bold); textview.setbackgroundcolor(this.context.getresources().getcolor(r.color.light_grayish_orange)); } textview.settext(str); container.addview(textview); return container; } }
i see other question don't understand behavior in case.
having generic parameters (the stuff in angle brackets) attached name of class telling java want users of class able specify types involved, , you're using names "variable names" types users choose. see, example, map<k,v>
, k
, v
represent types of map
's keys , values. when listed linearlayout
type parameter, compiler thought using placeholder other class users pick, , didn't know how construct one.
you're wanting concrete class extend class uses generics, know specific types want fill in there, don't put type parameters on own class, on 1 you're using. example, if writing custom map
class mapped string
s integer
s, public class mymap implements map<string, integer>
.
Comments
Post a Comment