Guest User

Untitled

a guest
Jan 16th, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.77 KB | None | 0 0
  1. interface TestInterface extends Callable<Void>{
  2. void doSomething(Future<Object> future, String id);
  3. }
  4.  
  5. class A{
  6. private Future<Object> future;
  7. private CustomInteraface a;
  8.  
  9. public A(Future<Object> future, CustomInteraface a){
  10. //do init
  11. }
  12. //getters and setters
  13. }
  14.  
  15. Class B implements TestInterface{
  16.  
  17. private HashMap<String, A> map = new HashMap();
  18. private static B monitor = new B();
  19.  
  20.  
  21. public Void call(){
  22. HashMap.Entry<String, A> pair = (HashMap.Entry<String, A>) it.next();
  23. A a = (A) pair.getValue();
  24. Future<Object> future = a.getFuture();
  25. // Do something
  26. }
  27.  
  28. public void doSomething(Future<Object> future, String id){
  29. if(map.contains(id)){
  30. //Do something
  31. }
  32. else{
  33. A a = new A(future, null);
  34. map.put();
  35. }
  36. }
  37.  
  38. }
  39.  
  40. interface TestInterface extends Callable<Void>{
  41. <T> void doSomething(Future<T> future, String id);
  42. }
  43.  
  44. class A<T>{
  45. private Future<T> future;
  46. private CustomInteraface a;
  47.  
  48. public A(Future<T> future, CustomInteraface a){
  49. //do init
  50. }
  51. //getters and setters
  52. }
  53.  
  54. Class B implements TestInterface{
  55.  
  56. private HashMap<String, A> map = new HashMap();
  57. private static B monitor = new B();
  58.  
  59.  
  60. public Void call(){
  61. HashMap.Entry<String, A> pair = (HashMap.Entry<String, A>) it.next();
  62. A a = (A) pair.getValue();
  63. //Code will definitely fail here as I'm trying to cast a future object of generic type to Object class
  64. Future<Object> future = a.getFuture();
  65. // Do something
  66. }
  67.  
  68. public void doSomething(Future<T> future, String id){
  69. if(map.contains(id)){
  70. //Do something
  71. }
  72. else{
  73. A<T> a = new A<T>(future, null);
  74. map.put();
  75. }
  76. }
  77.  
  78. }
Add Comment
Please, Sign In to add comment