fork download
  1. public class Main {
  2.  
  3. public interface FirstOperand {}
  4.  
  5. public interface SecondOperand {}
  6.  
  7. public interface Subtract<T extends FirstOperand,R extends SecondOperand> {
  8. T subtract(T that, T other);
  9. R subtract(T that, R other);
  10. R subtract(R that, T other);
  11. R subtract(R that, R other);
  12. }
  13.  
  14. public interface Add<T extends FirstOperand,R extends SecondOperand> {
  15. T add(T that, T other);
  16. R add(T that, R other);
  17. R add(R that, T other);
  18. R add(R that, R other);
  19. }
  20.  
  21.  
  22. public static abstract class MyFunctional {
  23.  
  24. public static<T extends FirstOperand, R extends SecondOperand> T
  25. compute(T a, T b, Subtract<T,R> substarcter) {
  26. return substarcter.subtract(a, b);
  27. }
  28.  
  29. public static<T extends FirstOperand, R extends SecondOperand> R
  30. compute(T a, R b, Subtract<T,R> substarcter) {
  31. return substarcter.subtract(a, b);
  32. }
  33.  
  34. public static<T extends FirstOperand, R extends SecondOperand> R
  35. compute(R a, T b, Subtract<T,R> substarcter) {
  36. return substarcter.subtract(a, b);
  37. }
  38. public static<T extends FirstOperand, R extends SecondOperand> R
  39. compute(R a, R b, Subtract<T,R> substarcter) {
  40. return substarcter.subtract(a, b);
  41. }
  42.  
  43. public static<T extends FirstOperand, R extends SecondOperand> T
  44. compute(T a, T b, Add<T,R> adder) {
  45. return adder.add(a, b);
  46. }
  47.  
  48. public static<T extends FirstOperand, R extends SecondOperand> R
  49. compute(T a, R b, Add<T,R> adder) {
  50. return adder.add(a, b);
  51. }
  52.  
  53. public static<T extends FirstOperand, R extends SecondOperand> R
  54. compute(R a, T b, Add<T,R> adder) {
  55. return adder.add(a, b);
  56. }
  57. public static<T extends FirstOperand, R extends SecondOperand> R
  58. compute(R a, R b, Add<T,R> adder) {
  59. return adder.add(a, b);
  60. }
  61.  
  62. static class
  63. Subtracter implements Subtract<FirstOperand, SecondOperand> {
  64.  
  65. @Override
  66. public FirstOperand subtract(FirstOperand that, FirstOperand other) {
  67. return null;
  68. }
  69.  
  70. @Override
  71. public SecondOperand subtract(FirstOperand that, SecondOperand other) {
  72. return null;
  73. }
  74.  
  75. @Override
  76. public SecondOperand subtract(SecondOperand that, FirstOperand other) {
  77. return null;
  78. }
  79.  
  80. @Override
  81. public SecondOperand subtract(SecondOperand that, SecondOperand other) {
  82. return null;
  83. }
  84. }
  85.  
  86. static class
  87. Adder implements Add<FirstOperand, SecondOperand> {
  88.  
  89. @Override
  90. public FirstOperand add(FirstOperand that, FirstOperand other) {
  91. return null;
  92. }
  93.  
  94. @Override
  95. public SecondOperand add(FirstOperand that, SecondOperand other) {
  96. return null;
  97. }
  98.  
  99. @Override
  100. public SecondOperand add(SecondOperand that, FirstOperand other) {
  101. return null;
  102. }
  103.  
  104. @Override
  105. public SecondOperand add(SecondOperand that, SecondOperand other) {
  106. return null;
  107. }
  108. }
  109.  
  110. }
  111.  
  112.  
  113. public static class A implements FirstOperand,SecondOperand {
  114. private int a;
  115. private int b;
  116.  
  117. public A(int a, int b){
  118. this.a=a;
  119. this.b=b;
  120. }
  121. public int getFirst(){
  122. return a;
  123. }
  124.  
  125. public int getSecond() {
  126. return b;
  127. }
  128.  
  129. @Override
  130. public String toString() {
  131. return "("+a+" "+b+")";
  132. }
  133. }
  134.  
  135. public static class B implements FirstOperand,SecondOperand {
  136. private int a;
  137. private int b;
  138. private int c;
  139.  
  140. public B(int a, int b, int c){
  141. this.a=a;
  142. this.b=b;
  143. this.c = c;
  144. }
  145. public int getFirst(){
  146. return a;
  147. }
  148.  
  149. public int getSecond() {
  150. return b;
  151. }
  152.  
  153. public int getThird() {
  154. return b;
  155. }
  156.  
  157. @Override
  158. public String toString() {
  159. return "("+a+" "+b+" "+c+")";
  160. }
  161. }
  162.  
  163. public static void main(String[] args) {
  164.  
  165. FirstOperand a = new A(1, 2);
  166. FirstOperand b = new A(1, 2);
  167.  
  168. FirstOperand c = new A(1, 2);
  169. SecondOperand d = new A(1, 2);
  170.  
  171. SecondOperand e = new A(1, 2);
  172. FirstOperand f = new A(1, 2);
  173.  
  174. SecondOperand g = new A(1, 2);
  175. SecondOperand h = new A(1, 2);
  176.  
  177. System.out.println("Hello World");
  178. System.out.println(MyFunctional.compute(a,b, new MyFunctional.Subtracter()));
  179. System.out.println(MyFunctional.compute(c,d, new MyFunctional.Subtracter()));
  180. System.out.println(MyFunctional.compute(e,f, new MyFunctional.Subtracter()));
  181. System.out.println(MyFunctional.compute(e,f, new MyFunctional.Subtracter()));
  182.  
  183. System.out.println(MyFunctional.compute(a,b, new MyFunctional.Adder()));
  184. System.out.println(MyFunctional.compute(c,d, new MyFunctional.Adder()));
  185. System.out.println(MyFunctional.compute(e,f, new MyFunctional.Adder()));
  186. System.out.println(MyFunctional.compute(e,f, new MyFunctional.Adder()));
  187.  
  188. FirstOperand i = new A(1, 2);
  189. FirstOperand j = new B(1, 2, 3);
  190.  
  191. FirstOperand k = new A(1, 2);
  192. SecondOperand l = new B(1, 2, 3);
  193.  
  194. SecondOperand m = new A(1, 2);
  195. FirstOperand n = new B(1, 2, 3);
  196.  
  197. SecondOperand o = new A(1, 2);
  198. SecondOperand p = new B(1, 2, 3);
  199.  
  200. System.out.println(MyFunctional.compute(i,j, new MyFunctional.Subtracter()));
  201. System.out.println(MyFunctional.compute(k,l, new MyFunctional.Subtracter()));
  202. System.out.println(MyFunctional.compute(m,n, new MyFunctional.Subtracter()));
  203. System.out.println(MyFunctional.compute(o,p, new MyFunctional.Subtracter()));
  204.  
  205. System.out.println(MyFunctional.compute(i,j, new MyFunctional.Adder()));
  206. System.out.println(MyFunctional.compute(k,l, new MyFunctional.Adder()));
  207. System.out.println(MyFunctional.compute(m,n, new MyFunctional.Adder()));
  208. System.out.println(MyFunctional.compute(o,p, new MyFunctional.Adder()));
  209.  
  210.  
  211. System.out.println("Bye");
  212. }
  213. }
  214.  
Success #stdin #stdout 0.1s 32484KB
stdin
Standard input is empty
stdout
Hello World
null
null
null
null
null
null
null
null
null
null
null
null
null
null
null
null
Bye