proxy - Java abstract visitor - guarantueed to succeed? If so, why? -
I was working with hibernate, using the visitor method, run-time class behind proxy instances by this address Trying to apply I then came with a The following code: this is a What guarantee does abstract welcome
approach, but I wonder if this will always give the right results. Consider
interface look (public void accept (Visitor v);} interface Visitor {public void Visit (Visitor visual host);} abstract class essence implements Visitable {@Override public void accept (visitor v) {v.visit (this);}} class Kankritvijet Aebstivetiv (public static void main) (string [] expand Arges) (last Vijitla visual = new Kankritvijetibl) Last Rshniy proxyVisitable = (city) Proxy.newProxyInstance (Thread.currentThread () getContextClassLoader (), a new class of & lt ;? & Gt; [] {Visitable.class}, New InvocationHandler () {@Override public Object invoke (Object proxy , method, object [] Arges) throws Throniy (return Methodkinvoke (visits, Arges);}}); proxyVisitable.accept (new comer () {public void visit (look visitorHost) @Override {println (visitorHost. getClass ());}});}}
ConcreteVisitable
which inherits
AbstractVisitable
Accept the method. In C ++, I, after the full risk of
, and not AbstractVisitable in this
AbstractVisitable :: can be referred to this ConcreteVisitable: : Will consider this
. I was worried that under certain circumstances the code will print the code class AbstractVisible
. Even then the output code class convergentable
, even if I hid the real type behind a dynamic proxy (the most difficult thing I could come up with). Abstract Visitor approach is guaranteed to work, or are there some disadvantages with this approach above? have been given in Java in this
indicator?
this
always indicates this object, as you guessed In the hierarchy you use it, it is irrelevant, unless you are using it in the context of non-virtual things (like private areas / methods, or God forbid, static methods). getClass ()
is virtual.
Now I hope that you are confusing the behavior of this
for Java's thinking. It's not that if you change your visitors to:
Classier Visitors {Public Zero Travel (Visitor Visual Host); Public Zero Travel (ConcreteVizitive VisitorHost); }
And then it was implemented like this:
Public Zero Travel (Visitors Visual Host) {System.out.println ("Visitable") ; } Public Zero Travel (ConcreteVizitator VisitorHost) {System.out.println ("ConcreteVidget"); }
This will actually print "visible", not "concrete widget", because Java does not execute.
Comments
Post a Comment