Skip to main content
deleted 1 characters in body
Source Link
Garth Gilmour
  • 11.3k
  • 5
  • 29
  • 36

It sounds like you are after something like this:

public static void test(MyInterface obj){ if(obj instanceof A) { A tmp = (A)obj; } else if(obj instanceof B) { B tmp = (B)obj; } else { //handle error condition } } 

But please note this is very bad form and indicates something has gone seriously wrong in your design. If you don't have control of the interface then, as suggested by marcj, adding a second interface might be the way to go. Note you havecan do this whilst preserving binary compatibility.

It sounds like you are after something like this:

public static void test(MyInterface obj){ if(obj instanceof A) { A tmp = (A)obj; } else if(obj instanceof B) { B tmp = (B)obj; } else { //handle error condition } } 

But please note this is very bad form and indicates something has gone seriously wrong in your design. If you don't have control of the interface then, as suggested by marcj, adding a second interface might be the way to go. Note you have do this whilst preserving binary compatibility.

It sounds like you are after something like this:

public static void test(MyInterface obj){ if(obj instanceof A) { A tmp = (A)obj; } else if(obj instanceof B) { B tmp = (B)obj; } else { //handle error condition } } 

But please note this is very bad form and indicates something has gone seriously wrong in your design. If you don't have control of the interface then, as suggested by marcj, adding a second interface might be the way to go. Note you can do this whilst preserving binary compatibility.

added 184 characters in body
Source Link
Garth Gilmour
  • 11.3k
  • 5
  • 29
  • 36

It sounds like you are after something like this:

public static void test(MyInterface obj){ if(obj instanceof A) { A tmp = (A)obj; } else if(obj instanceof B) { B tmp = (B)obj; } else { //handle error condition } } 

But please note this is very bad form and indicates something has gone seriously wrong in your design. If you don't have control of the interface then, as suggested by marcj, adding a second interface might be the way to go. Note you have do this whilst preserving binary compatibility.

It sounds like you are after something like this:

public static void test(MyInterface obj){ if(obj instanceof A) { A tmp = (A)obj; } else if(obj instanceof B) { B tmp = (B)obj; } else { //handle error condition } } 

But please note this is very bad form and indicates something has gone seriously wrong in your design.

It sounds like you are after something like this:

public static void test(MyInterface obj){ if(obj instanceof A) { A tmp = (A)obj; } else if(obj instanceof B) { B tmp = (B)obj; } else { //handle error condition } } 

But please note this is very bad form and indicates something has gone seriously wrong in your design. If you don't have control of the interface then, as suggested by marcj, adding a second interface might be the way to go. Note you have do this whilst preserving binary compatibility.

Source Link
Garth Gilmour
  • 11.3k
  • 5
  • 29
  • 36

It sounds like you are after something like this:

public static void test(MyInterface obj){ if(obj instanceof A) { A tmp = (A)obj; } else if(obj instanceof B) { B tmp = (B)obj; } else { //handle error condition } } 

But please note this is very bad form and indicates something has gone seriously wrong in your design.