// generics/ApplyTest.java// (c)2017 MindView LLC: see Copyright.txt// We make no guarantees that this code is fit for any purpose.// Visit http://OnJava8.com for more book information.import java.util.*;import java.util.function.*;import onjava.*;public class ApplyTest {public staticvoid main(String[] args) throws Exception {List<Shape> shapes =Suppliers.create(ArrayList::new, Shape::new, 3);Apply.apply(shapes,Shape.class.getMethod("rotate"));Apply.apply(shapes,Shape.class.getMethod("resize", int.class), 7);List<Square> squares =Suppliers.create(ArrayList::new, Square::new, 3);Apply.apply(squares,Shape.class.getMethod("rotate"));Apply.apply(squares,Shape.class.getMethod("resize", int.class), 7);Apply.apply(new FilledList<>(Shape::new, 3),Shape.class.getMethod("rotate"));Apply.apply(new FilledList<>(Square::new, 3),Shape.class.getMethod("rotate"));SimpleQueue<Shape> shapeQ = Suppliers.fill(new SimpleQueue<>(), SimpleQueue::add,Shape::new, 3);Suppliers.fill(shapeQ, SimpleQueue::add,Square::new, 3);Apply.apply(shapeQ,Shape.class.getMethod("rotate"));}}/* Output:Shape 0 rotateShape 1 rotateShape 2 rotateShape 0 resize 7Shape 1 resize 7Shape 2 resize 7Square 3 rotateSquare 4 rotateSquare 5 rotateSquare 3 resize 7Square 4 resize 7Square 5 resize 7Shape 6 rotateShape 7 rotateShape 8 rotateSquare 9 rotateSquare 10 rotateSquare 11 rotateShape 12 rotateShape 13 rotateShape 14 rotateSquare 15 rotateSquare 16 rotateSquare 17 rotate*/
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。