MethodHandle.AsFixedArity 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
建立 <一個 em>固定元</em> 方法的 handle ,其他方面等同於目前的方法 handle。
[Android.Runtime.Register("asFixedArity", "()Ljava/lang/invoke/MethodHandle;", "GetAsFixedArityHandler", ApiSince=26)]
public virtual Java.Lang.Invoke.MethodHandle? AsFixedArity();
[<Android.Runtime.Register("asFixedArity", "()Ljava/lang/invoke/MethodHandle;", "GetAsFixedArityHandler", ApiSince=26)>]
abstract member AsFixedArity : unit -> Java.Lang.Invoke.MethodHandle
override this.AsFixedArity : unit -> Java.Lang.Invoke.MethodHandle
傳回
一個只接受固定數量參數的新方法代柄
- 屬性
備註
建立 <一個 em>固定元</em> 方法的 handle ,其他方面等同於目前的方法 handle。
若目前方法的 handle 不是 #asVarargsCollector 變元數,則會回傳該方法的 handle 。 即使目前的方法 handle 無法作為有效輸入 asVarargsCollector,這點仍然成立。
否則,所得的固定元方法句柄具有與目前方法句柄相同的型別與行為,但該 #isVarargsCollector isVarargsCollector 代碼為假。 固定元數方法的handle可能是(也可能不是)為 asVarargsCollector的前一個參數。
以下是一個列表製作變數元數方法的範例: <blockquote>
{@code
MethodHandle asListVar = publicLookup()
.findStatic(Arrays.class, "asList", methodType(List.class, Object[].class))
.asVarargsCollector(Object[].class);
MethodHandle asListFix = asListVar.asFixedArity();
assertEquals("[1]", asListVar.invoke(1).toString());
Exception caught = null;
try { asListFix.invoke((Object)1); }
catch (Exception ex) { caught = ex; }
assert(caught instanceof ClassCastException);
assertEquals("[two, too]", asListVar.invoke("two", "too").toString());
try { asListFix.invoke("two", "too"); }
catch (Exception ex) { caught = ex; }
assert(caught instanceof WrongMethodTypeException);
Object[] argv = { "three", "thee", "tee" };
assertEquals("[three, thee, tee]", asListVar.invoke(argv).toString());
assertEquals("[three, thee, tee]", asListFix.invoke(argv).toString());
assertEquals(1, ((List) asListVar.invoke((Object)argv)).size());
assertEquals("[three, thee, tee]", asListFix.invoke((Object)argv).toString());
}
</區塊引用>
的 java.lang.invoke.MethodHandle.asFixedArity()Java 檔。
本頁部分內容為基於 Open Source Project 所創建與分享的作品,並依授權條款所描述的使用進行修改。