問題タブ [nested-generics]
For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.
java - フィールドが文字列名で参照されている場合に、汎用オブジェクトのフィールドのクラスを取得する方法
オブジェクトと文字列を受け取るメソッドがあります (文字列はオブジェクトのフィールドの名前です)。したがって、オブジェクト クラスからフィールドを取得し、field.get(object) を使用して値を取得します。しかし、フィールドが定義されたクラスにその値をキャストしたいと思います。@suppressWarnings("unchecked") を使用せずにそのキャストを行う方法はありますか?
これが私のコードです。1 つのオブジェクトのみを使用するように短縮しましたが、元のオブジェクトはオブジェクトのリストを使用し、マップ キーがフィールドのオブジェクトの値であり、マップ値がオブジェクトであるマップを返します。