Advertisement
Guest User

Untitled

a guest
Apr 18th, 2014
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. public void aMethod (MultipleObjects object){
  2.  
  3. object.commonMethod();
  4. // Do some stuff here
  5. }
  6.  
  7. interface MyInterface {
  8.  
  9. void commonMethod();
  10.  
  11. }
  12.  
  13. class MyClass implements MyInterface {
  14.  
  15. // implement `commonMethod()`
  16.  
  17. }
  18.  
  19. public void aMethod(MyInterface object) {
  20. ...
  21. object.commonMethod();
  22. ...
  23. }
  24.  
  25. public void aMethod(SomeInterface obj) {
  26. obj.commonMethod();
  27. // ...
  28. }
  29.  
  30. public interface SomeInterface {
  31. public void commonMethod();
  32. }
  33.  
  34. interface CommonMethodHaver {
  35. void commonMethod();
  36. }
  37.  
  38. class Class1 implements CommonMethodHaver {
  39. yadda yadda yadda;
  40. void commonMethod() {
  41. do class1-specific stuff here;
  42. }
  43. }
  44.  
  45. ...
  46. public void aMethod(CommonMethodHaver cmh) {
  47. cmh.commonMethod();
  48. // Do some stuff here
  49. }
  50.  
  51. public void aMethod(Object... object) {
  52. if(object==null)
  53. {
  54. //whatever you want to do if no parameters are entered.
  55. return;
  56. }
  57. for (Object o : object) {
  58. if (o == null) {
  59. continue; //what to do if null entered
  60. }
  61. if (o instanceof Integer) {
  62. //whatever you want to do if it is an Integer
  63. }
  64. else if(o instanceof Double)
  65. {
  66. //whatever you want to do if it is a Double
  67. }
  68. else if(o instanceof Character)
  69. {
  70. //whatever you want to do if it is a Character
  71. }
  72. //and so on
  73. }
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement