简体   繁体   中英

Class wrapper extending different base class

I have a Java project and now I also want to use this code for a GWT project so I don't have to write the same code twice. The problem is that some classes are not available in gwt, for example java.awt.geom.Rectangle2D.Double .

I was thinking of creating a wrapper class called RectangleWrapper that would extend either the standard Rectangle class or a gwt version of the same class.

In the shared code I would replace all my Rectangle2D.Double with my Rectangle and depending on a final boolean my wrapper class ( compiler flags java) would either extend on or the other Rectangle class.

Is this even possible or is there a better way to do this?

I just took one of my GWT-project client-side classes and added the following lines:

    if (false) {
        String a = StringEscapeUtils.escapeHtml("lalala");
    }

This obviously compiles just fine, but when I launch the GWT app I get this:

  ERROR: Errors in 'file:/C:/gwtproject/src/main/java/package/ClientSideClass.java'
    ERROR: Line 119: No source code is available for type org.apache.commons.lang.StringEscapeUtils; did you forget to inherit a required module?

So the answer would be no, you can't use a wrapper like that.

Is there any other way of achieving that? I highly doubt it.
One of the main features of GWT is replacing the old AWT/Swing desktop GUI components with a whole set of web GUI components designed for Javascript compatibility; there's no point in making the old components available or supported in any way.

If you were talking about utility libraries like Apache Commons, I could advise you to make an RPC call instead (client-side calls server-side where you can use anything you like, and return the results asynchronously), but that's not the case.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM