通用Java包名称 [英] Generic Java Package Name

查看:129
本文介绍了通用Java包名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我创建一个独立的Java程序时,该程序只有一个或两个Java/class文件,并且不与其他程序共享,因此,我从不花时间在包名称中说org.domain.scripts.purpose.我通常只是将我的主课设为main.Main.

When I create a stand-alone Java program, which only has one or two java/class files and is not shared with other programs, I never take the time to say org.domain.scripts.purpose in the package name. I typically just make my main class main.Main.

这可能是违反协议的,但是在复制程序以满足另一个小众需求时(例如将制表符转换为csv或递归列出按修改日期排序的文件),将不会使我重命名程序包名称或当我已经知道我所用的程序时,将遭受长软件包名称和路径的困扰.

Perhaps this is against protocol, but when duplicating a program in order to fill another small niche requirement (like converting tab delimited to csv or recursively listing files sorted by modify date), I will not be made to rename the package name or to suffer through long package names and paths when I already know what program I am in.

当通用类(例如Base64转换)没有唯一的程序包名称时,它们也很容易从一个程序复制到另一个程序.

Also little generic classes (like Base64 conversion) are easier to copy from one program to another when they do not have unique package names.

那么,什么是标准的通用软件包名称(或者有没有)

So, what would be a standard generic package name (or is there one)

我想我会继续提及其他一些原因.当它们具有相同的程序包名称时,比较文件或查看它们是否相同比较容易.另外,当我需要包含一个库时,我会写一个用法说明,其中包含java -cp library:jarfile而不是java -jar,并且cp选项要求我设置主类名称,因此我也希望在其中将其简称.同样,堆栈跟踪看起来也更好.

I suppose I will go ahead and mention some more reasons. It is easier to diff files or to see if they are identical when they have the same package name. Also, when I need a library to be included, I make a usage note that includes java -cp library:jarfile instead of java -jar and the cp option requires I set the main class name, so I like to have it short there too. Also the stack traces look better that way.

推荐答案

我认为与标准通用"软件包名称最接近的是默认软件包(如果需要,则为无软件包).当然,这是不好的做法,但我了解我们在谈论的是小型实验,而不是生产代码.

I think the closest thing to a "standard generic" package name would be the default package (or the no-package, if you like). Of course this is bad practice, but I understand we're talking about tiny experiments and not production code.

但是,默认程序包的主要缺点之一(除了缺少命名空间外)是无法从命名程序包中导入默认程序包中的类.

However, one of the major drawbacks of the default package (besides being merely the lack of a namespace) is that you cannot import classes in the default package from a named package.

因此,在您的实验中,如果只需要单段程序包名称,请使用适合您的任何名称:testpkgmain(如前所述)或其他...

Therefore, for your experiments, if you just want single-segment package names, go with whatever suits you: test, pkg, main (as you mentioned) or whatever...

这篇关于通用Java包名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆