public class MainActivity extends AppCompatActivity { private TextView textView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); textView = findViewById(R.id.textView); } private static class MyAsyncTask extends AsyncTask<Void, Void, String> { private TextView textView; public MyAsyncTask(TextView textView) { this.textView = textView; } @Override protected String doInBackground(Void... voids) { return "Hello World"; } @Override protected void onPostExecute(String result) { } } } public class EmployeeService { private EmployeeRepository employeeRepository; public EmployeeService(EmployeeRepository employeeRepository) { this.employeeRepository = employeeRepository; } public List<Employee> getAllEmployees() { return employeeRepository.getAllEmployees(); } } public class EmployeeRepository { public List<Employee> getAllEmployees() { return employees; } } @Configuration public class AppConfig { @Bean public EmployeeRepository employeeRepository() { return new EmployeeRepository(); } @Bean public EmployeeService employeeService(EmployeeRepository employeeRepository) { return new EmployeeService(employeeRepository); } } public class Main { public static void main(String[] args) { ApplicationContext context = new AnnotationConfigApplicationContext(AppConfig.class); EmployeeService employeeService = context.getBean(EmployeeService.class); List<Employee> employees = employeeService.getAllEmployees(); } } public class Player { private String name; private int level; public Player(String name) { this.name = name; this.level = 1; } public void levelUp() { this.level++; } } public class Game { public static void main(String[] args) { Player player = new Player("John"); player.levelUp(); } }


上一篇:
下一篇:
切换中文