クラスがあります
private class TouchCommand {
private int action;
private int x;
private int y;
...
コマンドを実行するときは、フィールド値-null / not nullを確認し、それに応じて縦方向のアクションを生成する必要があります。GoogleGuavaのオプションを使用したい。
どの解決策が正しいですか?これ:
public boolean executeCommand() {
Optional<Integer> optionalAction = Optional.fromNullable(action);
...
また:
private class TouchCommand {
private Optional<Integer> action;
private Optional<Integer> x;
private Optional<Integer> y;
...
parseActionの呼び出しもnullを返す(または存在しない)可能性があるとすると、次のようになります。
TouchCommand touchCommand = new TouchCommand();
touchCommand.mAction = parseAction(xmlParser.getAttributeValue(namespace, "action"));
...
質問:
- そうするかどうか:メソッドparseAction(および同様のもの)はオプションを返しますか?
- そうするかどうか:クラスオブジェクトのフィールドオプション?
- そうするかどうか:クラスのフィールドをチェックして(nullになる可能性があると仮定して)オブジェクトに変換する場合オプション?
どうも。