0

I often declare some constants to conditionally compile/not compile chunks of code. I put these constants on one class, then I use them all along the (big) app code.

Conf.java

    public static final int GUI_ACTIONBAR_HEIGHT=0;

elsewhere (example):

super.onCreate(savedInstanceState, Conf.GUI_ACTIONBAR_HEIGHT==0?R.layout.activity_funq_play_noactionbar:R.layout.activity_funq_play, true);

However, this triggers a warning "comparing identical expressions" in the case shown. It's obviously something I can live with, but I'd like to know if there's any SupressWarning magic to get rid of it (and the yellow warning icon in the sourcecode).

@SupressWarnings ("unused") 

doesnt't do the trick.

rupps
  • 9,712
  • 4
  • 55
  • 95

2 Answers2

0

This is a Java compilation warning and toggling it on/off really depends on the IDE. Assuming you are using Eclipse, you can navigate to the configurations by Preferences > Java > Compiler > Errors/Warning > Comparing identical values ('x==x') 'ignore' This should turn it off.

Some Noob Student
  • 14,186
  • 13
  • 65
  • 103
0

An ugly workaround that works in non static methods:

  1. Replace the static MyClass.CONSTANT access by a this.CONSTANT access.
  2. You will then have instead one "The static field MyClass.CONSTANT should be accessed in a static way" warning.
  3. This warning can be suppressed with a @SuppressWarnings("static-access") and no more comparison warning.

In your example this gives:

@SuppressWarnings("static-access")
public void onCreate(Object p1, Object p2, boolean b) {
    super.onCreate(savedInstanceState, this.GUI_ACTIONBAR_HEIGHT==0?R.layout.activity_funq_play_noactionbar:R.layout.activity_funq_play, true);
}

This workaround works only in non static methods.

Cédric
  • 334
  • 2
  • 8
  • thanks for the suggestion, however my use case is one "Configuration" class that holds different final booleans, so I configure a lot of application-wide tweaks in one centralized place! – rupps Feb 22 '15 at 15:06