What are the possibilities for self-modification o

2019-09-20 09:17发布

问题:

Could you list the possibilities for Java code to modify itself? The scenario in which this is going to be used is a learning program. In response to user input the program learns a new algorithm:

  1. it looks up the existing code base for a similar algorithm
  2. if no similar algorithm is in the code base, the program just adds a new algorithm
  3. if a similar algorithm exists, the program (perhaps with some help from the user) modifies the existing algorithm to be able to serve both the old purpose and the new purpose

A similar question exists Self modifying code in Java , but at that time the latest Java available was 6, and that question was closed as too broad.

回答1:

A Java program can dynamically compile and load automatically-generated classes (see JavaCompiler), but I don't think that it is what a machine-learning program would do. Most certainly, the programmer creates an algorithm depending on several parameters to estimate, and running the program simply consists in finding optimal values for those parameters.