クラスjava.lang.invoke.MethodType
の使用
パッケージ
説明
Javaプログラミング言語の設計にあたり基本的なクラスを提供します。
クラスやメソッド・ハンドルなどのランタイム・エンティティ用に「名目記述子」を表すクラスおよびインタフェース、および定数プール・エントリや
invokedynamic
コール・サイトなどのクラス・ファイル・エンティティ用に「名目記述子」を表すクラスおよびインタフェース。Javaランタイム外部のメモリーおよびファンクションへの低レベル・アクセスを提供します。
java.lang.invoke
パッケージは、Java Virtual Machineとやりとりするための低レベルのプリミティブを提供します。java.lang.runtime
パッケージでは、Java言語の低レベルのランタイム・サポートが提供されます。コレクション・フレームワーク、国際化サポート・クラス、サービス・ローダー、プロパティ、乱数生成、文字列解析とスキャン・クラス、Base64エンコーディングとデコード、ビット配列、およびその他のユーティリティ・クラスが含まれています。
invokedynamic
コール・サイトのリンクに使用されるインタフェースおよびクラスが含まれます。
独自の言語固有のオブジェクト・モデルおよび型変換を実装するために言語ランタイムに必要なインタフェースおよびクラスが含まれます。
言語ランタイムが独自の言語固有のオブジェクト・モデルおよび型変換を実装しやすくするために、一部のクラスの基本的な実装と様々なユーティリティを提供することで、より便利なクラスが含まれています。
-
java.langでのMethodTypeの使用
修飾子と型メソッド説明default MethodType
StackWalker.StackFrame.getMethodType()
このスタック・フレームによって表されるメソッドのパラメータ型と戻り値の型を表すMethodType
を返します。修飾子と型メソッド説明StringTemplate.Processor.Linkage.linkage
(List<String> fragments, MethodType type) このメソッドは、type
で指定された引数のある引数を指定して呼び出されると、テンプレート・プロセッサのプロセス・メソッドによって返される結果と等しい結果を返すMethodHandle
を作成します。 -
java.lang.constantでのMethodTypeの使用
-
java.lang.foreignでのMethodTypeの使用
-
java.lang.invokeでのMethodTypeの使用
修飾子と型メソッド説明final MethodType
VarHandle.accessModeType
(VarHandle.AccessMode accessMode) このVarHandleのアクセス・モード・タイプおよび特定のアクセス・モードを取得します。MethodType.appendParameterTypes
(Class<?>... ptypesToInsert) 追加のパラメータの型を持つメソッド型を検索または作成します。MethodType.appendParameterTypes
(List<Class<?>> ptypesToInsert) 追加のパラメータの型を持つメソッド型を検索または作成します。MethodType.changeParameterType
(int num, Class<?> nptype) 1つのパラメータの型が異なるメソッド型を検索または作成します。MethodType.changeReturnType
(Class<?> nrtype) 戻り値の型が異なるメソッド型を検索または作成します。MethodType.dropParameterTypes
(int start, int end) いくつかのパラメータの型が削除されたメソッド型を検索または作成します。MethodType.erase()
すべての参照型を消去してObject
にします。static MethodType
MethodType.fromMethodDescriptorString
(String descriptor, ClassLoader loader) 指定されたメソッド記述子(JVMS 4.3.3)のメソッド・タイプのインスタンスを検索または作成します。MethodType.generic()
すべての型(参照とプリミティブの両方)をObject
に変換します。static MethodType
MethodType.genericMethodType
(int objectArgCount) コンポーネントがすべてObject
であるようなメソッド型を検索または作成します。static MethodType
MethodType.genericMethodType
(int objectArgCount, boolean finalArray) Object
とオプションで末尾のObject[]
配列をコンポーネントに持つメソッド型を検索または作成します。MethodHandleInfo.getMethodType()
解決されたシンボリック参照の公称型をメソッド型として表現して返します。MethodType.insertParameterTypes
(int num, Class<?>... ptypesToInsert) 追加のパラメータの型を持つメソッド型を検索または作成します。MethodType.insertParameterTypes
(int num, List<Class<?>> ptypesToInsert) 追加のパラメータの型を持つメソッド型を検索または作成します。static MethodType
MethodType.methodType
(Class<?> rtype) 指定されたコンポーネントを持つメソッド型を検索または作成します。static MethodType
MethodType.methodType
(Class<?> rtype, Class<?> ptype0) 指定されたコンポーネントを持つメソッド型を検索または作成します。static MethodType
MethodType.methodType
(Class<?> rtype, Class<?>[] ptypes) 指定されたメソッド型のインスタンスを検索または作成します。static MethodType
MethodType.methodType
(Class<?> rtype, Class<?> ptype0, Class<?>... ptypes) 指定されたコンポーネントを持つメソッド型を検索または作成します。static MethodType
MethodType.methodType
(Class<?> rtype, MethodType ptypes) 指定されたコンポーネントを持つメソッド型を検索または作成します。static MethodType
MethodType.methodType
(Class<?> rtype, List<Class<?>> ptypes) 指定されたコンポーネントを持つメソッド型を検索または作成します。CallSite.type()
このコール・サイトのターゲットの型を返します。MethodHandle.type()
このメソッド・ハンドルの型を報告します。MethodType.unwrap()
すべてのラッパー型を対応するプリミティブ型に変換します。MethodType.wrap()
すべてのプリミティブ型を対応するラッパー型に変換します。修飾子と型メソッド説明static CallSite
LambdaMetafactory.altMetafactory
(MethodHandles.Lookup caller, String interfaceMethodName, MethodType factoryType, Object... args) 適切な型適応および引数の部分評価の後、指定されたMethodHandle
への委譲により、1つ以上のインタフェースを実装する単純な関数オブジェクトの作成を容易にします。final MethodHandle
MethodHandle.asType
(MethodType newType) 現在のメソッド・ハンドルの型を新しい型に適応させるアダプタ・メソッド・ハンドルを生成します。MethodHandles.Lookup.bind
(Object receiver, String name, MethodType type) 非staticメソッドの早期バインド・メソッド・ハンドルを生成します。static MethodHandle
MethodHandles.empty
(MethodType type) リクエストされた型のメソッド・ハンドルを生成します。引数は無視され、何も実行されず、戻り値の型に応じて適切なデフォルトが返されます。static MethodHandle
MethodHandles.exactInvoker
(MethodType type) 特殊なインボーカ・メソッド・ハンドルを生成します(これを使用すれば、指定された型の任意のメソッド・ハンドルを、invokeExact
を使用する場合と同様に呼び出すことができる)。static MethodHandle
MethodHandles.explicitCastArguments
(MethodHandle target, MethodType newType) 指定されたメソッド・ハンドルの型を新しい型に適応させるために、引数と戻り値の型の変換をペア単位で行うメソッド・ハンドルを生成します。MethodHandles.Lookup.findConstructor
(Class<?> refc, MethodType type) 指定された型のコンストラクタを使ってオブジェクトの作成と初期化を行うメソッド・ハンドルを生成します。MethodHandles.Lookup.findSpecial
(Class<?> refc, String name, MethodType type, Class<?> specialCaller) 仮想メソッドの早期にバインドされるメソッド・ハンドルを生成します。MethodHandles.Lookup.findStatic
(Class<?> refc, String name, MethodType type) staticメソッドのメソッド・ハンドルを生成します。MethodHandles.Lookup.findVirtual
(Class<?> refc, String name, MethodType type) 仮想メソッドのメソッド・ハンドルを生成します。static MethodHandle
MethodHandles.invoker
(MethodType type) 特殊なインボーカ・メソッド・ハンドルを生成します(これを使用すれば、指定された型と互換性のある任意のメソッド・ハンドルを、invoke
を使用する場合と同様に呼び出すことができる)。static CallSite
StringConcatFactory.makeConcat
(MethodHandles.Lookup lookup, String name, MethodType concatType) 最適化された文字列連結メソッドの作成を容易にします。このメソッドを使用すると、既知の型の引数(型の適応後や引数の部分評価後など)を効率的に連結できます。static CallSite
StringConcatFactory.makeConcatWithConstants
(MethodHandles.Lookup lookup, String name, MethodType concatType, String recipe, Object... constants) 最適化された文字列連結メソッドの作成を容易にします。このメソッドを使用すると、既知の型の引数(型の適応後や引数の部分評価後など)を効率的に連結できます。static CallSite
LambdaMetafactory.metafactory
(MethodHandles.Lookup caller, String interfaceMethodName, MethodType factoryType, MethodType interfaceMethodType, MethodHandle implementation, MethodType dynamicMethodType) 適切な型適応および引数の部分評価の後、指定されたMethodHandle
への委譲により、1つ以上のインタフェースを実装する単純な関数オブジェクトの作成を容易にします。static MethodType
MethodType.methodType
(Class<?> rtype, MethodType ptypes) 指定されたコンポーネントを持つメソッド型を検索または作成します。static MethodHandle
MethodHandles.permuteArguments
(MethodHandle target, MethodType newType, int... reorder) 引数の順序を変更することによって、指定されたメソッド・ハンドルの呼出し順序を新しい型に適応させるメソッド・ハンドルを生成します。static MethodHandle
MethodHandles.spreadInvoker
(MethodType type, int leadingArgCount) 指定されたtype
の任意のメソッド・ハンドルを呼び出すメソッド・ハンドルを生成しますが、その際、指定された数の末尾の引数が単一の末尾のObject[]
配列で置き換えられます。static String
MethodHandleInfo.toString
(int kind, Class<?> defc, String name, MethodType type) MethodHandleInfo
の文字列表現を、そのシンボリック参照の4つの部分を基に返します。static MethodHandle
MethodHandles.varHandleExactInvoker
(VarHandle.AccessMode accessMode, MethodType type) 特別な「呼び出しメソッドhandle」を生成します。このメソッドを使用して、関連付けられたアクセス・モード・タイプが指定のタイプと互換性がある任意のVarHandleでシグネチャ-多相アクセス・モード・メソッドを呼び出すことができます。static MethodHandle
MethodHandles.varHandleInvoker
(VarHandle.AccessMode accessMode, MethodType type) 特別な「呼び出しメソッドhandle」を生成します。このメソッドを使用して、関連付けられたアクセス・モード・タイプが指定のタイプと互換性がある任意のVarHandleでシグネチャ-多相アクセス・モード・メソッドを呼び出すことができます。修飾子コンストラクタ説明protected
ConstantCallSite
(MethodType targetType, MethodHandle createTargetHook) 永続的なターゲットを持つコール・サイトを作成します(コール・サイト自体にバインドされる場合があります)。MutableCallSite
(MethodType type) 指定されたメソッド型を持つ空のコール・サイト・オブジェクトを作成します。VolatileCallSite
(MethodType type) ターゲットへのvolatileバインディングを持つコール・サイトを作成します。 -
java.lang.runtimeでのMethodTypeの使用
修飾子と型メソッド説明static CallSite
SwitchBootstraps.enumSwitch
(MethodHandles.Lookup lookup, String invocationName, MethodType invocationType, Object... labels) 列挙型のターゲットにswitch
を実装するinvokedynamic
コール・サイトをリンクするためのブートストラップ・メソッド。static CallSite
TemplateRuntime.newLargeStringTemplate
(MethodHandles.Lookup lookup, String name, MethodType type) 大きな文字列テンプレートを作成するための文字列テンプレート・ブートストラップ・メソッド(つまり、値スロット数がStringConcatFactory.MAX_INDY_CONCAT_ARG_SLOTS
PREVIEWを超える場合)。static CallSite
TemplateRuntime.newStringTemplate
(MethodHandles.Lookup lookup, String name, MethodType type, String... fragments) 文字列テンプレートを作成するための文字列テンプレート・ブートストラップ・メソッド。static CallSite
TemplateRuntime.processStringTemplate
(MethodHandles.Lookup lookup, String name, MethodType type, MethodHandle processorGetter, String... fragments) 静的最終プロセッサの文字列テンプレート・ブートストラップ・メソッド。static CallSite
SwitchBootstraps.typeSwitch
(MethodHandles.Lookup lookup, String invocationName, MethodType invocationType, Object... labels) 参照タイプのターゲットにswitch
を実装するinvokedynamic
コール・サイトをリンクするためのブートストラップ・メソッド。 -
java.utilでのMethodTypeの使用
修飾子と型メソッド説明FormatProcessor.linkage
(List<String> fragments, MethodType type) MethodHandle
を作成します。StringTemplate
PREVIEWの値とともに指定すると、FormatProcessor.process(StringTemplate)
PREVIEWによって提供される結果と同等の結果が生成されます。 -
jdk.dynalinkでのMethodTypeの使用
修飾子と型メソッド説明final CallSiteDescriptor
CallSiteDescriptor.changeMethodType
(MethodType newMethodType) メソッド・タイプとこの記述子のみが異なるコール・サイト記述子を検索または作成します。protected CallSiteDescriptor
CallSiteDescriptor.changeMethodTypeInternal
(MethodType newMethodType) メソッド・タイプとこの記述子のみが異なるコール・サイト記述子を検索または作成します。修飾子コンストラクタ説明CallSiteDescriptor
(MethodHandles.Lookup lookup, Operation operation, MethodType methodType) 新しいコール・サイト記述子を作成します。 -
jdk.dynalink.linkerでのMethodTypeの使用
修飾子と型メソッド説明GuardedInvocation.asType
(MethodType newType) (戻り型がブール型に変更され、パラメータ数がガード用に切り捨てられる可能性があります)が1つある場合、呼出しとそのガードにMethodHandle.asType(MethodType)
が適用されたかのように、呼出しのタイプを変更します。GuardedInvocation.asType
(LinkerServices linkerServices, MethodType newType) (戻り型がブール型に変更され、パラメータ数がガード用に切り捨てられる可能性があります)が1つある場合、呼出しとそのガードにLinkerServices.asType(MethodHandle, MethodType)
が適用されたかのように、呼出しのタイプを変更します。LinkerServices.asType
(MethodHandle handle, MethodType fromType) MethodHandle.asType(MethodType)
と同様ですが、使用可能なすべてのGuardingTypeConverterFactory
実装によって生成されるメソッド・ハンドルのフックも使用され、言語固有の型強制パラメータを提供します。MethodTypeConversionStrategy.asType
(MethodHandle target, MethodType newType) メソッド・ハンドルを新しい型に変換します。default MethodHandle
LinkerServices.asTypeLosslessReturn
(MethodHandle handle, MethodType fromType) LinkerServices.asType(MethodHandle, MethodType)
と同様ですが、戻り値の型変換を特に処理します。GuardedInvocation.asTypeSafeReturn
(LinkerServices linkerServices, MethodType newType) 呼出しのタイプを変更します。LinkerServices.asTypeLosslessReturn(MethodHandle, MethodType)
が呼出しに適用され、LinkerServices.asType(MethodHandle, MethodType)
がガードに適用される((戻り型がブール型に変更され、パラメータ数がガード用に切り捨てられる可能性があります)が1つある場合)。 -
jdk.dynalink.linker.supportでのMethodTypeの使用
修飾子と型メソッド説明static MethodHandle
Guards.asType
(MethodHandle test, MethodType type) ガードとして使用するメソッド・ハンドルを取得し、リクエストされた型に適応しますが、booleanを返します。static MethodHandle
Guards.asType
(LinkerServices linkerServices, MethodHandle test, MethodType type) ガードとして使用するメソッド・ハンドルを取得し、リクエストされた型に適応しますが、booleanを返します。Lookup.findSpecial
(Class<?> declaringClass, String name, MethodType type) 基礎となるルックアップに対してMethodHandles.Lookup.findSpecial(Class, String, MethodType, Class)
を実行します。Lookup.findStatic
(Class<?> declaringClass, String name, MethodType type) 基礎となるルックアップに対してMethodHandles.Lookup.findStatic(Class, String, MethodType)
を実行します。Lookup.findVirtual
(Class<?> declaringClass, String name, MethodType type) 基礎となるルックアップに対してMethodHandles.Lookup.findVirtual(Class, String, MethodType)
を実行します。static MethodHandle
Guards.isArray
(int pos, MethodType type) 指定された位置の引数がJava配列である場合にtrueを返すメソッド・ハンドルを作成します。static MethodHandle
Guards.isInstance
(Class<?> clazz, int pos, MethodType type) 指定された型の引数を持つメソッド・ハンドルを作成しますが、ブール戻り値を使用します。static MethodHandle
Guards.isInstance
(Class<?> clazz, MethodType type) 指定された型の引数を持つメソッド・ハンドルを作成しますが、ブール戻り値を使用します。static MethodHandle
Guards.isOfClass
(Class<?> clazz, MethodType type) 指定された型の引数を持つガード・メソッド・ハンドルを作成しますが、ブール戻り値を使用します。