Java8 の新しい java.util.function.*pojo リフレクション メソッドを理解する (コード付き)
前回の記事「EOS ブロックチェーン グレープフルーツ ウォレット フロントエンド プラグインのスキャッター開発 (共有) の簡単な分析 」では、EOS ウォレット フロントの開発について学びました。ブロックチェーン内のプラグインの分散を終了します。次の記事では、新しい java.util.function.*pojo リフレクション メソッドについて紹介します。
コードに移動して例を見てください
通常の POJO を記述します
public class City { private String name; private String code; public City() { } public City(String name, String code) { this.name = name; this.code = code; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getCode() { return code; } public void setCode(String code) { this.code = code; } }
従来の方法
// Use a constructor with parameters to create a City City sf = new City("San Francisco", "SF"); // Use a default constructor with no parameters to create a City City la = new City(); // Set the members using setters la.setName("Los Angeles"); la.setCode("LA");
新しいゲッター アクセス方法
// Use the City's method references and assign them to functions Function<City, String> getNameFunction = City::getName; Function<City, String> getCodeFunction = City::getCode; System.out.println("The code for " + getNameFunction.apply(sf) + " is " + getCodeFunction.apply(sf)); -> The code for San Francisco is SF
新しいセッター アクセス メソッド
// Use the City's method references and assign them to biconsumers BiConsumer<City, String> setNameBiConsumer = City::setName; BiConsumer<City, String> setCodeBiConsumer = City::setCode; City ny = new City(); setNameBiConsumer.accept(ny, "New York"); setCodeBiConsumer.accept(ny, "NY");
コンストラクターにアクセスして新しいインスタンスを作成します
// Use the City's constructor method reference to create // a default constructor reference. Supplier<City> defaultConstructor = City::new; City sd = defaultConstructor.get(); sd.setName("San Diego"); sd.setCode("SD");
パラメータを使用したビルダー
// Use the City's constructor method reference to create // a two-parameter constructor reference. BiFunction<String, String, City> twoParameterConstructor = City::new; City dc = twoParameterConstructor.apply("Washington, D. C.", "DC");
推奨学習: Javaビデオチュートリアル
以上がJava8 の新しい java.util.function.*pojo リフレクション メソッドを理解する (コード付き)の詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。

ホットAIツール

Undresser.AI Undress
リアルなヌード写真を作成する AI 搭載アプリ

AI Clothes Remover
写真から衣服を削除するオンライン AI ツール。

Undress AI Tool
脱衣画像を無料で

Clothoff.io
AI衣類リムーバー

AI Hentai Generator
AIヘンタイを無料で生成します。

人気の記事

ホットツール

メモ帳++7.3.1
使いやすく無料のコードエディター

SublimeText3 中国語版
中国語版、とても使いやすい

ゼンドスタジオ 13.0.1
強力な PHP 統合開発環境

ドリームウィーバー CS6
ビジュアル Web 開発ツール

SublimeText3 Mac版
神レベルのコード編集ソフト(SublimeText3)

ホットトピック









Java8 は、minus() メソッドを使用して 1 年前の日付または 1 年後の日付を計算し、1 年前の日付を計算します。 packagecom.shxt.demo02;importjava.time.LocalDate;importjava.time.temporal.ChronoUnit;publicclassDemo09{publicstaticvoidmain(String[ ]args ){LocalDatetoday=LocalDate.now();LocalDateprevious Year=today.minus(1,ChronoUni

Java8 で 1 週間後の日付を計算する方法 この例では、1 週間後の日付を計算します。 LocalDate 日付には時間情報が含まれません。その plus() メソッドは、日、週、月を追加するために使用されます。これらの時間単位は ChronoUnit クラスで宣言されます。 LocalDate も不変型なので、戻った後に変数を使用して値を割り当てる必要があります。 packagecom.shxt.demo02;importjava.time.LocalDate;importjava.time.temporal.ChronoUnit;publicclassDemo08{publicstaticvoidmain(String[

Java8 の Clock クラス Java8 では、現在のタイムスタンプ、つまり現在のタイムゾーンの日付と時刻の情報を取得するための Clock クラスが追加されています。以前に System.currentTimeInMillis() と TimeZone.getDefault() が使用されていた場合は、Clock に置き換えることができます。 packagecom.shxt.demo02;importjava.time.Clock;publicclassDemo10{publicstaticvoidmain(String[]args){//現在のタイムベースを返します

Java8 で現在のタイムスタンプを取得します。Instant クラスには、次に示すように、現在のタイムスタンプを返す静的ファクトリ メソッド now() があります。 Instanttimestamp=Instant.now();System.out.println("このインスタントの値は何ですか"+timestamp.t

事前定義された書式設定ツールを使用して Java8 で日付を解析または書式設定する方法 packagecom.shxt.demo02;importjava.time.LocalDate;importjava.time.format.DateTimeFormatter;publicclassDemo17{publicstaticvoidmain(String[]args){StringdayAfterTommorrow="20180205 ";LocalDateformatted =LocalDate.parse

Java 8 でのタイムゾーンの処理 Java 8 では、日付と時刻を分離するだけでなく、タイムゾーンも分離します。特定のタイム ゾーンを処理する ZoneId や、特定のタイム ゾーンの時間を表す ZoneDateTime など、一連の個別のクラスが追加されました。これは、Java8 より前の GregorianCalendar クラスによって行われていました。次の例は、このタイム ゾーンの時刻を別のタイム ゾーンの時刻に変換する方法を示しています。 packagecom.shxt.demo02;importjava.time.LocalDateTime;importjava.time.ZoneId;importjava.time.ZonedDateT

Java8 で 2 つの日付が等しいかどうかを判断する packagecom.shxt.demo02;importjava.time.LocalDate;publicclassDemo04{publicstaticvoidmain(String[]args){LocalDatedate1=LocalDate.now();LocalDatedate2=LocalDate.of(2018,2,5) ;if(date1.equals(date2)){System.out.println("時間が等しい");}e

Java8 におけるパッケージcom.shxt.demo02;importjava.time.LocalDate;publicclassDemo14{publicstaticvoidmain(String[]args){LocalDatetoday=LocalDate.now();if(today.isLeap Year()){System.out.println( "今年は閏年");}else{System.out.println("2
