当我在Android中阅读设置源代码时,我发现了这段代码
public class Settings extends SettingsActivity {
/*
* Settings subclasses for launching independently.
*/
public static class BluetoothSettingsActivity extends SettingsActivity { /* empty */ }
public static class WirelessSettingsActivity extends SettingsActivity { /* empty */ }
public static class SimSettingsActivity extends SettingsActivity { /* empty */ }
public static class TetherSettingsActivity extends SettingsActivity { /* empty */ }
...
}
任何人都可以告诉我这样做有什么好处?我们可以直接使用SettingsActivity吗?
答案 0 :(得分:0)
在大多数情况下,它只是一种命名空间技术。这些示例在功能上是相同的,它们对public class A { // class A
public static class B { // class A.B
}
}
只有不同的用法。
public class A { // class A
}
public class B { // class B
}
public static
new Settings.BluetoothSettingsActivity()
内部类的行为与未嵌套的类完全相同。您必须首先给外部类访问内部类,例如:
static
如果没有指定`chef1.example.com ChefVault::Exceptions::KeysNotFound`
`chef1.example.com -----------------------------------`
`chef1.example.com myusers/testuser_keys_keys could not be found`
`chef1.example.com Cookbook Trace:`
`chef1.example.com Relevant File Content:
chef1.example.com ----------------------
chef1.example.com /var/chef/cache/cookbooks/user_management/recipes/default.rb:
chef1.example.com
chef1.example.com 30: require 'chef-vault'
chef1.example.com 31:
chef1.example.com 32: if node['user_management']['use_databag'] == true then
chef1.example.com 33: users = data_bag(node['user_management']['databag_name'])
chef1.example.com 34: sudoer_users = Array.new()
chef1.example.com 35: users.each do |id|
chef1.example.com 36:#user = data_bag_item(node['user_management']['databag_name'], id)
chef1.example.com 37>> user =ChefVault::Item.load(node['user_management']['databag_name'], id)
chef1.example.com 38: user_management user['id'] do
chef1.example.com 39: comment user['comment'] unless user['comment'].nil?
chef1.example.com 40: create_home user['create_home']
chef1.example.com 41: shell user['shell'] unless user['shell'].nil?
chef1.example.com 42: password user['password'] unless user['password'].nil?
chef1.example.com 43: uid user['uid'] unless user['uid'].nil?
chef1.example.com 44: gid user['gid'] unless user['gid'].nil?
chef1.example.com 45: ssh_keys user['ssh_keys'] unless user['ssh_keys'].nil?
chef1.example.com 46:delete_home_when_remove user['delete_home_when_remove'] unless user['delete_home_when_remove'].nil?`
,则会有很大的不同。请参阅this question。