Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@NIA
Created July 3, 2011 14:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NIA/1062263 to your computer and use it in GitHub Desktop.
Save NIA/1062263 to your computer and use it in GitHub Desktop.
OO-way checking for assertions
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!");
}
});
}
}
@mrsmith
Copy link

mrsmith commented Jul 5, 2011

KISS какбэ говорит "нет пути"

@NIA
Copy link
Author

NIA commented Jul 5, 2011

Да я и не утверждал, что этот путь есть тру :) Этот гист был сделан для иллюстрации в комменте к парфову посту, где нормальный способ проверки обозвали говнокодом.

@mrsmith
Copy link

mrsmith commented Jul 5, 2011

Это комент как раз к тому посту, просто там нельзя коментировать другой комент напрямую :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment