Java 2 Rust "compiler"

I don’t really understand the premise of this. Sure it’s a “naive” approach, bit in your project’s case this seems to mean that it doesn’t even create valid Rust syntax in most but the most trivial cases, at least judging by your example Employee.rs. And even if one improves upon the most obvious shortcomings, it’ll never be possible to just straightforward compile Java to Rust.

The lack of GC and real OO in Rust means that many Java idioms don’t translate directly into Rust, and on the other hand Java’s lack of Rust features means that the results will never be nowhere near realistic/useful Rust code. Even if you manage to get the result of such a translation “working” with—perhaps—some manual work, too, the code will never be structured in a way that’s idiomatic for Rust.

I recently read a thread discussing C to Rust compilation which, both being “systems programming” low-level languages and Rust supporting pretty much everything that C can do, might seem like a reasonable thing to try, but even that isn’t without problems. To quote an interesting reply in this topic:


So IMO, while this probably is, of course, a fun toy project, and maybe a great way for you to learn more about Rust syntax / the Rust language in general while you’re implementing this “Java 2 Rust “compiler””, I highly doubt that it can ever productively “help in java to rust translation”, as advertised.

3 Likes