自我复制的程序 [英] Programs that reproduces itself

查看:92
本文介绍了自我复制的程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以制作一个Java程序,将其源代码打印到一个新文件中,然后对其进行编译并运行该编译后的程序?

Is it possible to make a Java program that prints its source code to a new file, and compiles it, and runs the compiled program?

推荐答案

是的,有可能. 一个简单的实现是:使源代码包含在字符串中,将字符串保存到文件中,并用相同的字符串填充其自身的字符串(否则,初始字符串的大小将是无限的,这是由于此方法的递归方式)实现),然后编译该文件,然后运行已编译的文件(依次执行相同的操作).

Yes, it is possible. A trivial implementation would be: have the source code contain itself in a string, save the string to a file and fill its own string with the same string (otherwise, the initial string would be of infinite size, due to the recursive manner of this implementation), compile the file, and run the compiled file (which will, in turn, do the very same).

非平凡的实现要困难得多.

Non-trivial implementations are significantly harder.

这篇关于自我复制的程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆