意外的通用返回类型

时间:2017-11-19 16:17:52

标签: java generics

考虑这些课程:

class ParentComponent<T> {}
class ChildComponent<T> extends ParentComponent<T> {}
class Parent<C extends ParentComponent> { C component() {return null;} }
class Child<T> extends Parent<ChildComponent<T>> {}

Child类的实例化:

Child a = new Child();
ChildComponent ac = a.component(); // COMPILE ERROR! actual type is ParentComponent

Child<?> b = new Child<>();
ChildComponent bc = b.component(); // OK

Child<Object> c = new Child<>();
ChildComponent<?> cc = c.component(); // OK

Child<T> extends Parent<ChildComponent<T>> Child如何与ParentComponent成为Child

为什么java需要至少指定通配符才能推断出类型?

Isn&f; Child<Object>相当于Child<?>,而@api.multi @api.onchange('order_lines', 'order_lines.is_book_block', '') @api.constrains('order_lines', 'order_lines.isbn') def check_quantity(self): location = self.printer_book_block.property_stock_supplier.id for rec in self: if rec.order_lines: for line in rec.order_lines: if line.qty > line.isbn.with_context({ 'location': location, }).qty_available >= 0:#line.isbn.qty_available in location: rec.write({'state': 'awaitingraw'}) else: rec.write({'state': 'work_in_progress', 'is_book_block': True}) 相当于work_in_progess

0 个答案:

没有答案