java - Type of field 'myField' is concrete class 'MyClass' -
i preparing android application production have enabled lint warnings. 1 particular warning wide spread, don't understand it.
here warning:
type of field 'loginf' concrete class 'loginfragment'
and here description:
reports instance fields type declared concrete class, rather interface. such declarations may represent failure of abstraction, , may make testing more difficult. declarations classes come system or third-party libraries not reported inspection.
any elaboration appreciated.
note: ide using 'android studio'.
it's complaining because you're coupling class (which contains loginf field) loginfragment; if change loginfragment, may have change class.
alternatively, @ methods you're using on loginfragment in class. collectively form behaviour can specify in interface?
e.g. if method call on loginf initiatelogin(), perhaps can have:
interface login { void initiatelogin(); } class loginfragment extends fragment implements login { @override public void initiatelogin() { // login } } such instead of declaring loginfragment loginf = new loginfragment();, use login login = new loginfragment().
then can change loginfragment long keeps initiatelogin() method, or swap out new loginfragment() other implementation of login, might useful mocking in tests.
a contrived example. suggest using default lint config, not super strict one.
Comments
Post a Comment