gpt4 book ai didi

android - 包名以数字开头的规则是什么?

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:12:03 26 4
gpt4 key购买 nike

Android 中的包命名约定是:

com.organizationName.appName

但是如果 organizationName 或 appName 以数字或下划线开头,它将成为无效名称,因为 android 不接受以数字或下划线开头的单词。

例如:

com.1organizationName.appName 无效

重命名此包的约定是什么?

最佳答案

在官方"Naming a Package" java文档,它有如下语句:

In some cases, the internet domain name may not be a valid package name. This can occur if the domain name contains a hyphen or other special character, if the package name begins with a digit or other character that is illegal to use as the beginning of a Java name, or if the package name contains a reserved Java keyword, such as "int". In this event, the suggested convention is to add an underscore.

因此在您的情况下,它将是 com._1organizationname.appname

编辑:刚在 Android docs 中找到这个:

A full Java-language-style package name for the application. The name should be unique. The name may contain uppercase or lowercase letters ('A' through 'Z'), numbers, and underscores ('_'). However, individual package name parts may only start with letters.

很明显,它完全是 Java 风格的。不幸的是,在这种情况下,您最好的选择实际上是拼出数字,例如com.oneorganizationname.appname

关于android - 包名以数字开头的规则是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12041857/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com