小编wol*_*m77的帖子

如何获取 GitHub 存储库的描述?

每个GitHub 存储库都有一个描述 字段和一个可选的网站 字段。如何使用AJAX访问(任何 GitHub 存储库的)这些字段?

github github-api

6
推荐指数
1
解决办法
838
查看次数

`lookup.unreflect()`和`lookup.findVirtual()`有什么区别?

有两种方法我试图获得给定函数的MethodHandle.

方法1

Method m = MyClass.class.getMethod("myMethod", String.class, Map.class);
MethodHandle mh = MethodHandles.lookup().unreflect(m);
Run Code Online (Sandbox Code Playgroud)

方法2

MethodType type = MethodType.methodType(void.class, String.class, Map.class);
MethodHandle mh = MethodHandles.lookup().findVirtual(MyClass.class, "myMethod", type);
Run Code Online (Sandbox Code Playgroud)

它们之间有什么区别?

java reflection java-8

5
推荐指数
1
解决办法
772
查看次数

如何为字段创建功能接口实现?

考虑weightclass 中的一个字段Animal。我希望能够创建用于操作此字段的gettersetter功能接口对象。

class Animal {
  int weight;
}
Run Code Online (Sandbox Code Playgroud)

我目前的方法类似于用于方法的方法:

public static Supplier getter(Object obj, Class<?> cls, Field f) throws Exception {
  boolean isstatic = Modifier.isStatic(f.getModifiers());
  MethodType sSig = MethodType.methodType(f.getType());
  Class<?> dCls = Supplier.class;
  MethodType dSig = MethodType.methodType(Object.class);
  String dMthd = "get";
  MethodType dType = isstatic? MethodType.methodType(dCls) : MethodType.methodType(dCls, cls);
  MethodHandles.Lookup lookup = MethodHandles.lookup();
  MethodHandle fctry = LambdaMetafactory.metafactory(lookup, dMthd, dType, dSig, lookup.unreflectGetter(f), sSig).getTarget();
  fctry = !isstatic && obj!=null? fctry.bindTo(obj) : fctry;
  return (Supplier)fctry.invoke(); …
Run Code Online (Sandbox Code Playgroud)

java reflection java-8

4
推荐指数
2
解决办法
5372
查看次数

标签 统计

java ×2

java-8 ×2

reflection ×2

github ×1

github-api ×1