Whether I can use one file for all import things?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • markleo
    New Member
    • May 2022
    • 7

    Whether I can use one file for all import things?

    demo1.java:
    Code:
    import a;
    import b;
    import c;
    import d;
    demo2.java:
    Code:
    import b;
    import c;
    import d;
    import e;
    import f;
    I have an idea, I just use one import_file file for doing the import things, then demo1.java and demo2.java just need import the import_file once, it can make our java code more brevity.

    just like this:

    import_file
    Code:
    import a;
    import b;
    import c;
    import d;
    import e;
    import f;
    demo1.java

    Code:
    import import_file
    demo2.java

    Code:
    import import_file
    I want to know does my idea work? are there any drawbacks?
  • NeoPa
    Recognized Expert Moderator MVP
    • Oct 2006
    • 32653

    #2
    Hi Mark.

    I'm not sure if you noticed, but you posted this into the Lounge by mistake. It's obviously very important that questions be posted in the appropriate forum if you want helpful answers and to avoid irritating those in the Lounge.

    I've assumed it's a Java question, rather than JavaScript, so let me know if I have that wrong.

    Comment

    • BloomS
      New Member
      • Jan 2023
      • 8

      #3
      This idea would work and can make your Java code more succinct. There are no drawbacks to this approach, as long as all the imports that are required are present in the import_file. It may be helpful to organize the imports in the import_file alphabetically or by category to make it easier to find the needed imports.

      Comment

      • markleo
        New Member
        • May 2022
        • 7

        #4
        Thanks, it should be under java category.

        Comment

        • NeoPa
          Recognized Expert Moderator MVP
          • Oct 2006
          • 32653

          #5
          Excellent Mark.

          And you've also got, what looks to me like, a very helpful answer already.

          I took the liberty of marking it as BestAnswer as it seems to deal with your question appropriately (from my non-java expert perspective at least).

          Comment

          Working...