Multiline Strings in Java 11
Taeber Rapczak <taeber@rapczak.com>
Tuesday 7 February 2023
Introduction
This past weekend I had an idea of using an Annotation Processor to convert comments into multiline strings in Java 11.
/**
SELECT Name, PhoneNumber
FROM Event, Volunteer
WHERE Event.ID = ${id}
AND Volunteer.City = ${city}
*/
@Multiline
String template = "";
// ... is transformed at compile-time into...
String template = ""
+ "SELECT Name, PhoneNumber "
+ " FROM Event, Volunteer "
+ " WHERE Event.ID = ${id} "
+ " AND Volunteer.City = ${city}";
I came up with something close. Check it out on GitHub: github.com/taeber/java-multiline