Although it is possible to inject an entire preference node, sometimes it is more convenient to inject just a single preference value. This can reduce the amount of code needed to extract and use a preference value. In addition, this can remove the runtime dependency on IEclipsePreferences
, which can make the code more portable.
IEclipsePreferences
node with an int launchCount
field, and append value = "launchCount"
to the @Preferences
annotation:@Preference(nodePath = "com.packtpub.e4.clock.ui", value = "launchCount") @Inject // IEclipsePreferences preferences; int launchCount;
launchCount
value directly:System.out.println("Launch count is: " + launchCount);
Instead of injecting the entire preferences node, the single preference value is injected. If the preference value doesn't exist, then it will be assigned a default value (0
for numeric values, false
for boolean, and null
for object values). By removing the IEclipsePreferences
and Preferences
interfaces, the code is less tied to the Eclipse framework (the runtime visible annotation @Preference
is still present, but this isn't required at runtime by the application outside of an Eclipse environment).
3.145.170.65