先来看下两个方法的官方注释:
/**
* Gets the decoded authority part of this URI. For
* server addresses, the authority is structured as follows:
* {@code [ userinfo '@' ] host [ ':' port ]}
*
* <p>Examples: "google.com", "bob@google.com:80"
*
* @return the authority for this URI or null if not present
*/
/**
* 从这个 URI 中获取解码后的 authority
* 对于服务器地址, authority 的结构是酱紫的 : {@code [ userinfo '@' ] host [ ':' port ]}
*
* 例如 : "google.com", "bob@google.com:80"
*
* @return 返回这个 URI 的 authority, 或者返回 null (如果不存在)
*/
@Nullable
public abstract String getAuthority();
/**
* Gets the encoded host from the authority for this URI. For example,
* if the authority is "bob@google.com", this method will return
* "google.com".
*
* @return the host for this URI or null if not present
*/
/**
* 从这个 URI 的 authority 中获取编码后的 host
* 例如 : 如果 authority 是 "bob@google.com", 那该方法会返回 "google.com".
*
* @return 返回这个 URI 的 host, 或者返回 null (如果不存在)
*/
@Nullable
public abstract String getHost();
通俗理解就是 host
是 authority
的子串,authority
可以包含端口,而 host
不含端口。
看个栗子:
http://www.example.com/
authority = www.example.com
host = www.example.com
http://255.255.255.255:8080/
authority = 255.255.255.255:8080
host = 255.255.255.255