Created
July 3, 2011 14:24
-
-
Save NIA/1062263 to your computer and use it in GitHub Desktop.
OO-way checking for assertions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface CodeBlock { | |
public void invoke(); | |
} | |
public class Preprocessor { | |
public static void invokeIfAssertsEnabled(CodeBlock block) { | |
boolean assertsEnabled = false; | |
assert assertsEnabled = true; | |
if (assertsEnabled) { | |
block.invoke(); | |
} | |
} | |
} | |
public class Main { | |
public static void main(String[] args) { | |
Preprocessor.invokeIfAssertsEnabled(new CodeBlock() { | |
public void invoke() { | |
System.out.println("Asserts Enabled!"); | |
} | |
}); | |
} | |
} |
Да я и не утверждал, что этот путь есть тру :) Этот гист был сделан для иллюстрации в комменте к парфову посту, где нормальный способ проверки обозвали говнокодом.
Это комент как раз к тому посту, просто там нельзя коментировать другой комент напрямую :)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
KISS какбэ говорит "нет пути"