code_junkie

When do you use Java's @Override annotation and why?

Nov 11th, 2011
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. protected boolean displaySensitiveInformation() {
  2. return false;
  3. }
  4.  
  5. protected boolean displaySensitiveInformation(Context context) {
  6. return true;
  7. }
  8.  
  9. someUIComponent.addMouseListener(new MouseAdapter(){
  10. public void mouseEntered() {
  11. ...do something...
  12. }
  13. });
  14.  
  15. public class Bigram {
  16. private final char first;
  17. private final char second;
  18. public Bigram(char first, char second) {
  19. this.first = first;
  20. this.second = second;
  21. }
  22. public boolean equals(Bigram b) {
  23. return b.first == first && b.second == second;
  24. }
  25. public int hashCode() {
  26. return 31 * first + second;
  27. }
  28.  
  29. public static void main(String[] args) {
  30. Set<Bigram> s = new HashSet<Bigram>();
  31. for (int i = 0; i < 10; i++)
  32. for (char ch = 'a'; ch <= 'z'; ch++)
  33. s.add(new Bigram(ch, ch));
  34. System.out.println(s.size());
  35. }
  36. }
Add Comment
Please, Sign In to add comment