0

I understand what I am asking for in the following question has almost no practical application, but I want to know if it is possible to do in Java.

I want to be able to define athrows declaration with two words (the first word to be ignored and the second word to be treated as a valid exception type, which it will be).

So basically I want a method signature that looks like this to compile:

public void foo() throws A Fit {}

Where the word 'A' is simply ignored and then I would have Fit defined as a custom exception (as you would normally do this) like:

public class Fit extends Exception {
  public Fit(String msg) {
    super(msg);
  }
}

So in essence I am asking if I can somehow tell Java to ignore a specific textual 'keyword' (in this instance 'A'). Thus, define keyword 'A' to do nothing. I know you can do this in C by defining keywords via #define, but does Java offer this capability in any way?

lax1089
  • 3,403
  • 3
  • 17
  • 37

1 Answers1

1

Short answer: No. Java is pretty strict and straightforward about keywords

You can play with ANTLR and Java's Grammar to achieve something similar, as shown by this other SO answer: Add or modify keywords in java language

everton
  • 7,579
  • 2
  • 29
  • 42