Is there a way to do the following? Check if a class exists (in the same package) and if it does exist, check if a particular method exists, and if so, calling it?

Say that I have class X. In some method of class X, I want to do the following:

```
if (class Y exists) { //Maybe use Class.forName("Y")?
  if ( Y has method a(String, String) ) {
    call Y.a("hello", "world");
  }
}

```

Is such a thing possible? And is doing such a thing reasonable? Thanks.