r/learnjava • • Jul 06 '22

F string For Java

Hello Everyone,

I Have created F string for java using reflection api.

Kindly check the below utility.

All contributions will help.

Thanks :)

https://github.com/chinmay-sawant/FString-For-Java

2 Upvotes

14 comments sorted by

View all comments

7

u/xRageNugget Jul 06 '22

That sounds like string format with extra steps!

1

u/chinmay06 Jul 06 '22

Yes brother it is but i am trying to explore is there any direct way we can implement it in our environment so that we don't have to call it multiple times.

6

u/Fletsky Jul 06 '22

I never used fstring in python, so I didn't know how it work. But after reading your code, documentation and examples, I still don't have any idea how it is supposed to work. Is that some statefull String formatter? How is it used in python?

About code I have one advice. It is not a good idea to catch all exceptions and just print stack trace. It would be better to leave exception handling to user, so he can catch those exceptions himself and decide what he wants to do with it.

2

u/chinmay06 Jul 06 '22

Yes about the exception you are right ! But as mentioned on the page I am learning java and new to java I have worked in python though

In python you only write print(f"Your message {yourvariable}") for printing or even for any type of string a=f"{declaredVariable}"

in java as you know we have to use .format or printf with variable substitution ;_ which atleast i feel hectic as i have come on java from python ;)

2

u/loomynartylenny Jul 06 '22

I never used fstring in python, so I didn't know how it work.

Well, this explains Python's fstrings, if that's of any interest to you: https://peps.python.org/pep-0498/