本文整理汇总了Java中java.lang.invoke.SerializedLambda类的典型用法代码示例。如果您正苦于以下问题:Java SerializedLambda类的具体用法?Java SerializedLambda怎么用?Java SerializedLambda使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SerializedLambda类属于java.lang.invoke包,在下文中一共展示了SerializedLambda类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: checkInput
import java.lang.invoke.SerializedLambda; //导入依赖的package包/类
@Override
public ObjectInputFilter.Status checkInput(FilterInfo filter) {
count++;
if (filter.serialClass() != null) {
if (filter.serialClass().getName().contains("$$Lambda$")) {
// TBD: proper identification of serialized Lambdas?
// Fold the serialized Lambda into the SerializedLambda type
classes.add(SerializedLambda.class);
} else if (Proxy.isProxyClass(filter.serialClass())) {
classes.add(Proxy.class);
} else {
classes.add(filter.serialClass());
}
}
this.maxArray = Math.max(this.maxArray, filter.arrayLength());
this.maxRefs = Math.max(this.maxRefs, filter.references());
this.maxDepth = Math.max(this.maxDepth, filter.depth());
this.maxBytes = Math.max(this.maxBytes, filter.streamBytes());
return ObjectInputFilter.Status.UNDECIDED;
}
示例2: checkInput
import java.lang.invoke.SerializedLambda; //导入依赖的package包/类
@Override
public ObjectInputFilter.Status checkInput(FilterInfo filter) {
Class<?> serialClass = filter.serialClass();
System.out.printf(" checkInput: class: %s, arrayLen: %d, refs: %d, depth: %d, bytes; %d%n",
serialClass, filter.arrayLength(), filter.references(),
filter.depth(), filter.streamBytes());
count++;
if (serialClass != null) {
if (serialClass.getName().contains("$$Lambda$")) {
// TBD: proper identification of serialized Lambdas?
// Fold the serialized Lambda into the SerializedLambda type
classes.add(SerializedLambda.class);
} else if (Proxy.isProxyClass(serialClass)) {
classes.add(Proxy.class);
} else {
classes.add(serialClass);
}
}
this.maxArray = Math.max(this.maxArray, filter.arrayLength());
this.maxRefs = Math.max(this.maxRefs, filter.references());
this.maxDepth = Math.max(this.maxDepth, filter.depth());
this.maxBytes = Math.max(this.maxBytes, filter.streamBytes());
return ObjectInputFilter.Status.UNDECIDED;
}
示例3: createLambdaObject
import java.lang.invoke.SerializedLambda; //导入依赖的package包/类
@SuppressWarnings({ "rawtypes", "unchecked" })
private SerializedValue createLambdaObject(Type type, Object object) {
SerializedValue serializedObject = serialized.get(object);
if (serializedObject == null) {
SerializedLambda serializedLambda = Lambdas.serializeLambda(object);
try {
Class<?> functionalInterfaceType = classFrom(serializedLambda.getFunctionalInterfaceClass());
Serializer serializer = fetchSerializer(serializedLambda.getClass());
serializedObject = serializer.generate(type, functionalInterfaceType);
serialized.put(object, serializedObject);
if (serializedObject instanceof SerializedReferenceType) {
((SerializedReferenceType) serializedObject).setId(identityHashCode(object));
}
serializer.populate(serializedObject, serializedLambda);
} catch (RuntimeException e) {
throw new SerializationException(e);
}
}
return serializedObject;
}
示例4: fetchSerializer
import java.lang.invoke.SerializedLambda; //导入依赖的package包/类
private Serializer<?> fetchSerializer(Class<?> clazz) {
Serializer<?> serializer = serializers.get(clazz);
if (serializer != null) {
return serializer;
}
if (clazz.isArray()) {
serializer = new ArraySerializer(this);
} else if (clazz.isEnum() || (clazz.getSuperclass() != null && clazz.getSuperclass().isEnum())) {
serializer = new EnumSerializer(this);
} else if (SerializedLambda.class == clazz) {
serializer = new LambdaSerializer(this);
} else {
serializer = new GenericSerializer(this);
}
return serializer;
}
示例5: populate
import java.lang.invoke.SerializedLambda; //导入依赖的package包/类
@Override
public void populate(SerializedLambdaObject serializedLambda, Object object) {
if (!(object instanceof SerializedLambda)) {
return;
}
SerializedLambda lambda = (SerializedLambda) object;
serializedLambda.setSignature(new LambdaSignature()
.withCapturingClass(lambda.getCapturingClass())
.withInstantiatedMethodType(lambda.getInstantiatedMethodType())
.withFunctionalInterface(
lambda.getFunctionalInterfaceClass(),
lambda.getFunctionalInterfaceMethodName(),
lambda.getFunctionalInterfaceMethodSignature())
.withImplMethod(lambda.getImplClass(), lambda.getImplMethodKind(), lambda.getImplMethodName(), lambda.getImplMethodSignature()));
List<SerializedValue> arguments = IntStream.range(0, lambda.getCapturedArgCount())
.mapToObj(lambda::getCapturedArg)
.map(o -> facade.serialize(o.getClass(), o))
.collect(toList());
serializedLambda.setCapturedArguments(arguments);
}
示例6: testReferencedLambdaExpression
import java.lang.invoke.SerializedLambda; //导入依赖的package包/类
public void testReferencedLambdaExpression() {
final LambdaKeeper keeper = new LambdaKeeper();
keeper.keep((Callable<String> & Serializable)() -> "result");
keeper.reference();
final String expected = ""
+ "<keeper>\n"
+ " <callable resolves-to=\"serialized-lambda\">\n"
+ " <capturingClass>com.thoughtworks.acceptance.LambdaTest</capturingClass>\n"
+ " <functionalInterfaceClass>java/util/concurrent/Callable</functionalInterfaceClass>\n"
+ " <functionalInterfaceMethodName>call</functionalInterfaceMethodName>\n"
+ " <functionalInterfaceMethodSignature>()Ljava/lang/Object;</functionalInterfaceMethodSignature>\n"
+ " <implClass>com/thoughtworks/acceptance/LambdaTest</implClass>\n"
+ " <implMethodName>lambda$0</implMethodName>\n"
+ " <implMethodSignature>()Ljava/lang/String;</implMethodSignature>\n"
+ " <implMethodKind>6</implMethodKind>\n"
+ " <instantiatedMethodType>()Ljava/lang/String;</instantiatedMethodType>\n"
+ " <capturedArgs/>\n"
+ " </callable>\n"
+ " <referenced class=\"java.util.concurrent.Callable\" reference=\"../callable\"/>\n"
+ "</keeper>";
xstream.alias("keeper", LambdaKeeper.class);
xstream.allowTypes(SerializedLambda.class);
assertBothWaysNormalized(keeper, expected);
}
示例7: serialized
import java.lang.invoke.SerializedLambda; //导入依赖的package包/类
default SerializedLambda serialized() {
try {
Method replaceMethod = getClass().getDeclaredMethod("writeReplace");
replaceMethod.setAccessible(true);
return (SerializedLambda) replaceMethod.invoke(this);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
示例8: method
import java.lang.invoke.SerializedLambda; //导入依赖的package包/类
default Method method() {
SerializedLambda lambda = serialized();
Class<?> containingClass = getContainingClass();
return Arrays.asList(containingClass.getDeclaredMethods())
.stream()
.filter(method -> Objects.equals(method.getName(), lambda.getImplMethodName()))
.findFirst()
.orElseThrow(UnableToGuessMethodException::new);
}
示例9: nameOf
import java.lang.invoke.SerializedLambda; //导入依赖的package包/类
private static String nameOf(PropertyToMatch<?, ?> property) {
Optional<String> propertyName = Stream.<Class<?>>iterate(property.getClass(), Class::getSuperclass)
.flatMap(c -> Arrays.stream(c.getDeclaredMethods()))
.filter(m -> m.getName().equals("writeReplace"))
.map(m -> (SerializedLambda) invoke(m, property))
.map(SerializedLambda::getImplMethodName)
.findFirst();
return propertyName.orElseThrow(() -> new RuntimeException("Unable to determine property name."));
}
示例10: LambdaInfo
import java.lang.invoke.SerializedLambda; //导入依赖的package包/类
public LambdaInfo(Object lambda, Kind kind, SerializedLambda serializedLambda, Method functionalMethod, Method implementationMethod) {
this.lambda = lambda;
this.kind = kind;
this.serializedLambda = serializedLambda;
this.functionalMethod = functionalMethod;
this.implementationMethod = implementationMethod;
}
示例11: fnToFieldName
import java.lang.invoke.SerializedLambda; //导入依赖的package包/类
public static String fnToFieldName(Fn fn) {
try {
Method method = fn.getClass().getDeclaredMethod("writeReplace");
method.setAccessible(Boolean.TRUE);
SerializedLambda serializedLambda = (SerializedLambda) method.invoke(fn);
String getter = serializedLambda.getImplMethodName();
String fieldName = Introspector.decapitalize(getter.replace("get", ""));
return fieldName;
} catch (ReflectiveOperationException e) {
throw new ReflectionOperationException(e);
}
}
示例12: assertDeserializeMethod
import java.lang.invoke.SerializedLambda; //导入依赖的package包/类
private void assertDeserializeMethod(Class<?> clazz, boolean expectedPresent) {
try {
Method m = clazz.getDeclaredMethod("$deserializeLambda$", SerializedLambda.class);
if (!expectedPresent)
fail("Unexpected $deserializeLambda$ in " + clazz);
}
catch (NoSuchMethodException e) {
if (expectedPresent)
fail("Expected to find $deserializeLambda$ in " + clazz);
}
}
示例13: saveGame
import java.lang.invoke.SerializedLambda; //导入依赖的package包/类
private void saveGame() {
xstream.autodetectAnnotations(true);
xstream.allowTypes(new Class[] {SerializedLambda.class});
spritesCopy = new ArrayList<>();
for (Sprite sprite : spriteModel.getSprites()) {
spritesCopy.add(sprite.clone());
}
savedSpritesXML = xstream.toXML(spritesCopy);
}
示例14: where
import java.lang.invoke.SerializedLambda; //导入依赖的package包/类
public <T> IsPojo<A> where(
final MethodReference<A, T> methodReference,
final Matcher<T> returnValueMatcher) {
final SerializedLambda serializedLambda = serializeLambda(methodReference);
ensureDirectMethodReference(serializedLambda);
return where(
serializedLambda.getImplMethodName(),
methodReference,
returnValueMatcher);
}
示例15: ensureDirectMethodReference
import java.lang.invoke.SerializedLambda; //导入依赖的package包/类
private static void ensureDirectMethodReference(final SerializedLambda serializedLambda) {
final Method targetMethod;
try {
final Class<?> implClass = Class.forName(serializedLambda.getImplClass().replace('/', '.'));
targetMethod = findMethodByName(implClass, serializedLambda.getImplMethodName());
} catch (NoSuchMethodException | ClassNotFoundException e) {
throw new IllegalStateException(
"serializeLambda returned a SerializedLambda pointing to an invalid class/method", e);
}
if (targetMethod.isSynthetic()) {
throw new IllegalArgumentException("The supplied lambda is not a direct method reference");
}
}