java - What is the Difference between returning IModel<?> and <M> IModel<M>? -
there library/framework utilize lot has methods this:
public imodel<?> getdefaultmodel() { /* implementation here */ } using method fine, want phone call container.getdefaultmodel().getobject().foo(). however, because getdefaultmodel() returns imodel<?> means getobject() returns object.
so i'm forced use:
((bar)container.getdefaultmodel().getobject()).foo() or
((imodel<bar>)container.getdefaultmodel()).getobject().foo() but if method had been specified this:
public <m> imodel<m> getdefaultmodel() { /* implementation here */ } then use: container.<bar>getdefaultmodel().getobject().foo() think much nicer/cleaner syntax.
the framework writers smart people, i'm curious, other casting syntax, differences there in 2 different definitions?
while we're on subject, , please allow me know if should separate question. since generics code uses compile time check instead of runtime cast, generate faster runtime code, explicit cast version?
there no other differences. difference lies purely in syntax. imodel<?>, casting has done explicitly (as noted). however, using generics, tell compiler cast bar when returning getobject() method, don't have cast yourself. other that, exact same thing happens in both cases.
java generics wicket
No comments:
Post a Comment