Java 後置補完テンプレートのリスト
この表は、Java コードで使用できる後置補完テンプレートをまとめたものです。
名前 | 説明 | 例: 前 | 例: 後 |
---|---|---|---|
| ブール式を否定します。 |
public class Foo {
void m(boolean b) {
m(b!);
}
}
|
public class Foo {
void m(boolean b) {
m(!b);
}
}
|
| オブジェクトを関数呼び出しでラップします。 |
public class Foo {
void m(Object o) {
o.arg
}
}
|
public class Foo {
void m(Object o) {
call(o)
}
}
|
| ブール式からアサーションを作成します。 |
public void m(boolean value) {
value.assert
}
|
public void m(boolean value) {
assert value;
}
|
| 式をキャストで囲みます。 |
public class Foo {
void m(Object o) {
o.cast
}
}
|
public class Foo {
void m(Object o) {
(() o)
}
}
|
| 型キャストを使用して式の新しい変数を作成します。 |
void m(Object o) {
if (o instanceof String) {
o.castvar
}
}
|
void m(Object o) {
if (o instanceof String) {
String o = (String)o;
}
}
|
| ブール式が false であることを確認するチェックを追加します。 |
public class Foo {
void m(boolean b) {
b.else
}
}
|
public class Foo {
void m(boolean b) {
if (!b) {
}
}
}
|
| 式のフィールドを導入します。 |
public class Foo {
public Foo(int arg) {
arg.field
}
}
|
public class Foo {
private int foo;
public Foo(int arg) {
foo = arg;
}
}
|
| 列挙可能なコレクションを反復処理します。 |
public class Foo {
void m() {
int[] values = {1, 2, 3};
values.for
}
}
|
public class Foo {
void m() {
int[] values = {1, 2, 3};
for (int value : values) {
}
}
}
|
| コレクションに対してインデックスを反復処理します。 |
public class Foo {
void m() {
int foo = 100;
foo.fori
}
}
|
public class Foo {
void m() {
int foo = 100;
for (int i = 0; i < foo; i++) {
}
}
}
|
| String.format 呼び出しを作成します。 |
public void m(String value) {
value.format
}
|
public void m(String value) {
String.format(value, );
}
|
| インデックスを逆の順序で繰り返します。テンプレートを配列またはリストで使用して、その要素を逆の順序で反復することもできます。 |
public class Foo {
void m() {
int foo = 100;
foo.forr
}
}
|
public class Foo {
void m() {
int foo = 100;
for (int i = foo; i > 0; i--) {
}
}
}
|
| ブール式が true であることを検証するチェックを追加します。 |
public class Foo {
void m(boolean b) {
b.if
}
}
|
public class Foo {
void m(boolean b) {
if (b) {
}
}
}
|
| 式を instanceof で囲みます。 |
public class Foo {
void m(Object o) {
o.inst
}
}
|
public class Foo {
void m(Object o) {
o instanceof ? (() o) : null;
}
}
|
| 式を instanceof で囲みます。 |
public class Foo {
void m(Object o) {
o.instanceof
}
}
|
public class Foo {
void m(Object o) {
o instanceof ? (() o) : null;
}
}
|
| 列挙可能なコレクションを反復処理します。 |
public class Foo {
void m() {
int[] values = {1, 2, 3};
values.iter
}
}
|
public class Foo {
void m() {
int[] values = {1, 2, 3};
for (int value : values) {
}
}
}
|
| 式をラムダで囲みます。 |
public void m() {
foo().lambda
}
|
public void m() {
() -> foo()
}
|
| クラスの新しい呼び出しを挿入します。 |
Foo.new
|
new Foo()
|
| 式が null ではないことを確認するチェックを追加します。 |
public class Foo {
void m(Object o) {
o.nn
}
}
|
public class Foo {
void m(Object o) {
if (o != null){
}
}
}
|
| ブール式を否定します。 |
public class Foo {
void m(boolean b) {
m(b.not);
}
}
|
public class Foo {
void m(boolean b) {
m(!b);
}
}
|
| 式が null ではないことを確認するチェックを追加します。 |
public class Foo {
void m(Object o) {
o.notnull
}
}
|
public class Foo {
void m(Object o) {
if (o != null){
}
}
}
|
| 式が null であることを確認するチェックを追加します。 |
public class Foo {
void m(Object o) {
o.null
}
}
|
public class Foo {
void m(Object o) {
if (o == null){
}
}
}
|
| オプションのオブジェクトを作成します。 |
public void m(int intValue, double doubleValue, long longValue, Object objValue) {
intValue.opt
doubleValue.opt
longValue.opt
objValue.opt
}
|
public void m(int intValue, double doubleValue, long longValue, Object objValue) {
OptionalInt.of(intValue)
OptionalDouble.of(doubleValue)
OptionalLong.of(longValue)
Optional.ofNullable(objValue)
}
|
| 式を括弧で囲みます。 |
public class Foo {
void m(Object o) {
o.par
}
}
|
public class Foo {
void m(Object o) {
(o)
}
}
|
| オブジェクトを Objects.requireNonNull でラップします。 |
public class Foo {
void m(Object o) {
o.reqnonnull
}
}
|
public class Foo {
void m(Object o) {
Objects.requireNonNull(o)
}
}
|
| 含まれているメソッドから値を返します。 |
public class Foo {
String m() {
"result".return
}
}
|
public class Foo {
String m() {
return "result";
}
}
|
| System.err.println 呼び出しを作成します。 |
public class Foo {
void m(boolean b) {
b.serr
}
}
|
public class Foo {
void m(boolean b) {
System.err.println(b);
}
}
|
| System.out.printf 呼び出しを作成します。 |
public class Foo {
void m(boolean b) {
b.souf
}
}
|
public class Foo {
void m(boolean b) {
System.out.printf("", b);
}
}
|
| System.out.println 呼び出しを作成します。 |
public class Foo {
void m(boolean b) {
b.sout
}
}
|
public class Foo {
void m(boolean b) {
System.out.println(b);
}
}
|
| 出力された値の呼び出しの説明を含む System.out.println を作成します。 |
public class Foo {
void m(boolean b) {
b.soutv
}
}
|
public class Foo {
void m(boolean b) {
System.out.println("b = " + b);
}
}
|
| Arrays.stream 呼び出しを作成します。 |
public void m(String[] array) {
array.stream
}
|
public void m(String[] array) {
Arrays.stream(array)
}
|
| 整数 / 列挙型 / 文字列値の切り替えを生成します。 |
public enum Foo {
A, B, C;
void f(Foo foo) {
foo.switch
}
}
|
public enum Foo {
A, B, C;
void f(Foo foo) {
switch (foo) {
}
}
}
|
| 同期ステートメントを生成します。 |
public class Foo {
void m(Object o) {
o.synchronized
}
}
|
public class Foo {
void m(Object o) {
synchronized (o) {
}
}
}
|
| Flux/Mono を actor.test.StepVerifier.create メソッド呼び出しでラップします。 |
public void m() {
Flux.just(1).test
Flux.just(2).testN
}
|
public void m() {
StepVerifier.create(Flux.just(1))
StepVerifier.create(Flux.just(2), )
}
|
| Flux/Mono を actor.test.StepVerifier.create メソッド呼び出しでラップします。 |
public void m() {
Flux.just(1).test
Flux.just(2).testN
}
|
public void m() {
StepVerifier.create(Flux.just(1))
StepVerifier.create(Flux.just(2), )
}
|
| Throwable 型の式をスローします。 |
public class Foo {
void m() {
new RuntimeException("error").throw
}
}
|
public class Foo {
void m() {
throw new RuntimeException("error");
}
}
|
| 適切な RxJava2 または RxJava3 Completable ファクトリで式をラップします。 |
public void m(Throwable error,
String s,
Future<Integer> future,
Callable<String> callable,
Single<String> single) {
error.toCompletable
s.toCompletable
future.toCompletable
callable.toCompletable
single.toCompletable
}
|
public void m(Throwable error,
String s,
Future<Integer> future,
Callable<String> callable,
Single<String> single) {
Completable.error(error)
Completable.complete()
Completable.fromFuture(future)
Completable.fromCallable(callable)
Completable.fromSingle(single)
}
|
| 適切な RxJava2 または RxJava3 Flowable ファクトリで式をラップします。 |
public void m(Throwable error,
String s,
List<Integer> list,
String[] array,
Publisher<Integer> p,
Stream<Integer> stream) {
error.toFlowable
s.toFlowable
list.toFlowable
array.toFlowable
p.toFlowable
stream.toFlowable
}
|
public void m(Throwable error,
String s,
List<Integer> list,
String[] array,
Publisher<Integer> p,
Stream<Integer> stream) {
Flowable.error(error)
Flowable.just(s)
Flowable.fromIterable(list)
Flowable.fromArray(array)
Flowable.fromPublisher(p)
Flowable.fromStream(stream)
}
|
| 式を適切な actor.core.publisher.Flux ファクトリでラップします。 |
public void m(Throwable error,
String s,
List<Integer> list,
String[] array,
Mono<Integer> mono,
Stream<Integer> stream) {
error.toFlux
s.toFlux
list.toFlux
array.toFlux
mono.toFlux
stream.toFlux
}
|
public void m(Throwable error,
String s,
List<Integer> list,
String[] array,
Mono<Integer> mono,
Stream<Integer> stream) {
Flux.error(error)
Flux.just(s)
Flux.fromIterable(list)
Flux.fromArray(array)
Flux.from(mono)
Flux.fromStream(stream)
}
|
| 式を適切な RxJava2 または RxJava3 の Maybe ファクトリでラップします。 |
public void m(Throwable error,
String s,
Future<Integer> future,
Callable<String> callable,
Single<String> single) {
error.toMaybe
s.toMaybe
future.toMaybe
callable.toMaybe
single.toMaybe
}
|
public void m(Throwable error,
String s,
Future<Integer> future,
Callable<String> callable,
Single<String> single) {
Maybe.error(error)
Maybe.just(s)
Maybe.fromFuture(future)
Maybe.fromCallable(callable)
Maybe.fromSingle(single)
}
|
| 式を適切な actor.core.publisher.Mono ファクトリでラップします。 |
public void m(Throwable error,
String s,
CompletableFuture<Integer> future,
Callable<String> callable,
Mono<Integer> mono,
Supplier<Double> sup) {
error.toMono
s.toMono
future.toMono
callable.toMono
mono.toMono
sup.toMono
}
|
public void m(Throwable error,
String s,
CompletableFuture<Integer> future,
Callable<String> callable,
Mono<Integer> mono,
Supplier<Double> sup) {
Mono.error(error)
Mono.just(s)
Mono.fromFuture(future)
Mono.fromCallable(callable)
Mono.from(mono)
Mono.fromSupplier(sup)
}
|
| 適切な RxJava2 または RxJava3 Observable ファクトリで式をラップします。 |
public void m(Throwable error,
String s,
List<Integer> list,
String[] array,
Publisher<Integer> p,
Stream<Integer> stream) {
error.toObservable
s.toObservable
list.toObservable
array.toObservable
p.toObservable
stream.toObservable
}
|
public void m(Throwable error,
String s,
List<Integer> list,
String[] array,
Publisher<Integer> p,
Stream<Integer> stream) {
Observable.error(error)
Observable.just(s)
Observable.fromIterable(list)
Observable.fromArray(array)
Observable.fromPublisher(p)
Observable.fromStream(stream)
}
|
| 適切な RxJava2 または RxJava3 Single ファクトリで式をラップします。 |
public void m(Throwable error,
String s,
Future<Integer> future,
Callable<String> callable,
Maybe<String> maybe) {
error.toSingle
s.toSingle
future.toSingle
callable.toSingle
maybe.toSingle
}
|
public void m(Throwable error,
String s,
Future<Integer> future,
Callable<String> callable,
Maybe<String> maybe) {
Single.error(error)
Single.just(s)
Single.fromFuture(future)
Single.fromCallable(callable)
Single.fromMaybe(maybe)
}
|
| try-catch ブロックにステートメントを挿入します。 |
public void m2() {
m().try
}
public void m() throws CheckedException { }
|
public void m2() {
try {
m();
} catch(CheckedException e) {
e.printStackTrace();
}
}
public void m() throws CheckedException { }
|
| try-with-resources ブロックにステートメントを挿入します (Java 7 以降が必要です)。 |
public class Foo {
void m() {
getStream().twr
}
AutoCloseable getStream()
{
return null;
}
}
|
public class Foo {
void m() {
try (AutoCloseable stream = getStream()) {
} catch (Exception e) {
}
}
AutoCloseable getStream()
{
return null;
}
}
|
| 式に lombok.val 変数を導入します。 |
public class Foo {
void m(Object o) {
String.valueOf(123).val
}
}
|
public class Foo {
void m(Object o) {
lombok.val foo = String.valueOf(123);
}
}
|
| 式に変数を導入します。 |
public class Foo {
void m(Object o) {
o instanceof String.var
}
}
|
public class Foo {
void m(Object o) {
boolean foo = o instanceof String;
}
}
|
| 式に lombok.var 変数を導入します。 |
public class Foo {
void m(Object o) {
String.valueOf(123).varl
}
}
|
public class Foo {
void m(Object o) {
lombok.var foo = String.valueOf(123);
}
}
|
| ブールステートメントが true の間、反復されます。 |
public class Foo {
void m(boolean x) {
x.while
return;
}
}
|
public class Foo {
void m(boolean x) {
while (x) {
}
return;
}
}
|
関連ページ:

Java ライブテンプレートのリスト
ライブテンプレートを使用して、ループ、条件、宣言、print ステートメントなどの一般的な構造をコードに挿入します。この表は、Java コードで使用できるライブテンプレートをまとめたものです。でサラウンド:Callable<Object> callable = new Callable<Object>() { public Object call() throws Exception { } }; またはの後にブランチを追加します。else if() { } 反復ループを作成...

Kotlin 入門
このチュートリアルは、JetBrains、Fleet で Kotlin 開発を始めるのに役立ちます。インストール、プロジェクトのセットアップ、Kotlin コードの操作について説明します。前提条件:JetBrains Toolbox をダウンロードしてインストールする JetBrains Toolbox をダウンロードしてインストールします。macOS の場合、プロセッサーの種類 (Apple Silicon または Intel) に一致するインストーラーをダウンロードすることもできます。システム...