fork download
  1. public class Main {
  2.  
  3. public interface IBar<T> {
  4. public void start(Foo<T> foo);
  5. }
  6.  
  7. public static class Bar<T> implements IBar<T> {
  8.  
  9. public void start(final Foo<T> foo) {
  10. new Thread() {
  11. @Override
  12. public void run() {
  13. while (true) {
  14. T baz = foo.getT();
  15. //do something with the T baz object
  16. foo.callBack();
  17. }
  18. }
  19. }.start();
  20. }
  21.  
  22. }
  23.  
  24. public static class Foo<T> {
  25. private T baz;
  26. private Bar<T> bar;
  27.  
  28. public Foo(T baz, Bar<T> bar) {
  29. this.baz = baz;
  30. this.bar = bar;
  31. }
  32.  
  33. public void startBar() {
  34. bar.start(this); // totally possible
  35. }
  36.  
  37. public T getT() {
  38. return baz;
  39. }
  40.  
  41. public void callBack() {
  42. System.out.println("called back");
  43. }
  44. }
  45.  
  46. public static void main(String[] a) {
  47. System.out.println("compiled and ran");
  48. }
  49. }
Success #stdin #stdout 0.06s 380160KB
stdin
Standard input is empty
stdout
compiled and ran