What is the purpose of annotations in Java? I have this fuzzy idea of them as somewhere in between a comment and actual code. Do they affect the program at run time?
When do you use Java's @Override annotation and why? The link refers to a question on when one should use the override annotation(@override).. This might help understand the concept of annotation better.Check out.
Anders gives a good summary, and here's an example of a JUnit annotation
@Test(expected=IOException.class)
public void flatfileMissing() throws IOException {
readFlatFile("testfiles"+separator+"flatfile_doesnotexist.dat");
}
Here the @Test
annotation is telling JUnit that the flatfileMissing
method is a test that should be executed and that the expected result is a thrown IOException
. Thus, when you run your tests, this method will be called and the test will pass or fail based on whether an IOException
is thrown.