<small id='4dF5Q'></small><noframes id='4dF5Q'>

  • <legend id='4dF5Q'><style id='4dF5Q'><dir id='4dF5Q'><q id='4dF5Q'></q></dir></style></legend>
      <bdo id='4dF5Q'></bdo><ul id='4dF5Q'></ul>

  • <i id='4dF5Q'><tr id='4dF5Q'><dt id='4dF5Q'><q id='4dF5Q'><span id='4dF5Q'><b id='4dF5Q'><form id='4dF5Q'><ins id='4dF5Q'></ins><ul id='4dF5Q'></ul><sub id='4dF5Q'></sub></form><legend id='4dF5Q'></legend><bdo id='4dF5Q'><pre id='4dF5Q'><center id='4dF5Q'></center></pre></bdo></b><th id='4dF5Q'></th></span></q></dt></tr></i><div id='4dF5Q'><tfoot id='4dF5Q'></tfoot><dl id='4dF5Q'><fieldset id='4dF5Q'></fieldset></dl></div>
      <tfoot id='4dF5Q'></tfoot>

      1. Java 包导入别名

        时间:2023-09-27
          <i id='oMWZZ'><tr id='oMWZZ'><dt id='oMWZZ'><q id='oMWZZ'><span id='oMWZZ'><b id='oMWZZ'><form id='oMWZZ'><ins id='oMWZZ'></ins><ul id='oMWZZ'></ul><sub id='oMWZZ'></sub></form><legend id='oMWZZ'></legend><bdo id='oMWZZ'><pre id='oMWZZ'><center id='oMWZZ'></center></pre></bdo></b><th id='oMWZZ'></th></span></q></dt></tr></i><div id='oMWZZ'><tfoot id='oMWZZ'></tfoot><dl id='oMWZZ'><fieldset id='oMWZZ'></fieldset></dl></div>
          <legend id='oMWZZ'><style id='oMWZZ'><dir id='oMWZZ'><q id='oMWZZ'></q></dir></style></legend>

        • <small id='oMWZZ'></small><noframes id='oMWZZ'>

              1. <tfoot id='oMWZZ'></tfoot>
                  <tbody id='oMWZZ'></tbody>
                  <bdo id='oMWZZ'></bdo><ul id='oMWZZ'></ul>
                  本文介绍了Java 包导入别名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  在 Java 中是否可以导入包并为这个包导入一个特定的名称?

                  Is it possible in Java to import packages and give this package import a specific name?

                  我目前有一个类,它使用来自后端和服务包的一些 DTO.在这两个包中,DTO 具有相同的名称.而且我认为这不太可读:

                  I currently have a class, which uses some DTO's from a backend and a service package. In both packages the DTO's have the same name. And I think this isn't quite readable:

                  com.backend.mypackage.a.b.c.d.UserDto userBackend = new com.backend.mypackage.a.b.c.d.UserDto();
                  com.service.mypackage.a.b.c.d.UserDto userService = new com.service.mypackage.a.b.c.d.UserDto();
                  
                  mapper(userBackend, userService);
                  

                  这是一个小例子.该类实际上非常复杂,并且其中包含更多代码.

                  This is a small example. The class is actually quite complex and has a lot more code in it.

                  Java 是否有类似 import com.backend.mypackage.a.b.c.d.UserDto as userDtoBackend 这样我可以缩短我的源代码?

                  Does Java have something like import com.backend.mypackage.a.b.c.d.UserDto as userDtoBackend so i can shorten my source code?

                  推荐答案

                  不行,不能import x as y;"在 Java 中.

                  No, you can not do "import x as y;" in Java.

                  您可以做的是扩展类,或为其编写一个包装类,然后导入该类.

                  What you CAN do is to extend the class, or write a wrapper class for it, and import that one instead.

                  import com.backend.mypackage.a.b.c.UserDto;
                  
                  public class ImportAlias {
                      static class UserDtoAlias extends com.backend.mypackage.a.b.c.d.UserDto {
                      }
                  
                      public static void main(String[] args) {
                          UserDto userBackend = new UserDto();
                          UserDtoAlias userService = new UserDtoAlias();
                  
                          mapper(userBackend, userService);
                      }
                  
                      private static void mapper(UserDto userBackend, UserDtoAlias userService) {
                          // ...
                      }
                  }
                  

                  这篇关于Java 包导入别名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:javac如何自动编译一个类的依赖 下一篇:如何判断 Selenium for Java 中是否选中了一个复选框

                  相关文章

                  最新文章

                  • <bdo id='aUspg'></bdo><ul id='aUspg'></ul>
                  <tfoot id='aUspg'></tfoot>

                      <legend id='aUspg'><style id='aUspg'><dir id='aUspg'><q id='aUspg'></q></dir></style></legend>
                      <i id='aUspg'><tr id='aUspg'><dt id='aUspg'><q id='aUspg'><span id='aUspg'><b id='aUspg'><form id='aUspg'><ins id='aUspg'></ins><ul id='aUspg'></ul><sub id='aUspg'></sub></form><legend id='aUspg'></legend><bdo id='aUspg'><pre id='aUspg'><center id='aUspg'></center></pre></bdo></b><th id='aUspg'></th></span></q></dt></tr></i><div id='aUspg'><tfoot id='aUspg'></tfoot><dl id='aUspg'><fieldset id='aUspg'></fieldset></dl></div>

                      <small id='aUspg'></small><noframes id='aUspg'>