13

Project Lombokは、Eclipseでのコードテンプレート/コード生成と比較して何か利点がありますか?(.jarを含める以外に)欠点はありますか?

4

5 に答える 5

21

One advantage of Lombok is that once you've annotated a class with, say, the @Data annotation, you never need to regenerate the code when you make changes. For example, if you add a new field, @Data would automatically include that field in the equals, hashCode and toString methods. You'd need to manually make that change when using Eclipse generated methods. Some of the time, you may prefer the manual control but for most cases, I expect not.

于 2010-04-11T11:15:32.033 に答える
12

The advantage of Lombok is that the code isn't actually there - i.e. classes are much more readable and are not cluttered.

于 2010-04-11T10:54:42.337 に答える
6

Advantages:

  • Very easy to use
  • Classes are much cleaner ('no boilerplate code'), especially 'struct'-like inner classes shrink to a bare minimum:

    @Data private class AttrValue { private String attribute; private MyType value; }

    This will create both getters and setters, a toString(), and correct hash() / equals() methods including both variables. The variant with @Value creates an immutable structure (no setters, all fields final).

  • No need to generate/remove code when you change fields (getters, setters, toString, hash, equals)
  • No interference with hand-coded methods: just add you own specific setter to the class where needed. Lombok skips this and generates everything else

Disadvantages:

  • No name refactoring, yet: renaming value above will not (yet) rename getValue() and setValue()
  • May slows down ecplise slightly
  • toString output not as nice as, for instance, ToStringBuilder from apache commons
于 2010-11-03T10:16:10.937 に答える
4

頭に浮かぶのはごくわずかです。

  • これはアノテーションに基づいているため、Java5より前のレガシープロジェクトには適していません(delombokが役立ちます)。実際には、javacv1.6コンパイラを使用する必要があります。
  • 複数のコンストラクターに関してはまだ制限があります

依存関係の問題は見落とされるべきではありませんが、あなたはそれをあなたの質問から除外しました。

于 2010-04-11T10:50:44.523 に答える
1

Eclipse EMF offers some features which are very handy which Lombock does not yet support:

  • Powerful notification mechanims to get informed about changes in your instances
  • Generic API without java reflection. Access and modify instances without a strong reference to the type
  • Command und API based editing
  • Cross references between models: Create and load model trees and EMF handles the loading by creating a proxy for the cross reference. This saves memory and boost performance in huge domain trees
  • And much more...
于 2015-02-11T13:30:07.393 に答える