[This was April Fool’s, obviously]
Under the guidance provided by the ‘Keep it Secret, Keep it Safe’ (KISKIS) principle, secret is a proposed new keyword under Java 1.9.
This keyword is designed to be used in cases where an open and extensible API is required, but certain functional parts of the API should be restricted to developers of a certain level of experience / competency. These especially include methods that could, if used correctly, violate the internal state of the object, but which are nonetheless required to exist due to legacy limitations and backwards compatibility.
As a practical example, say we had an object CoreComponent .
1 2 3 4 5 6 7 |
public class CoreComponent { public void resetInternalState() { // logic that could violate state } } |
Given that this method should only be used by certain developers, we mark it secret .
1 2 3 4 5 6 7 |
public class CoreComponent { public secret void resetInternalState() { // logic that could violate state } } |
This indicates to IDEs, JavaDocs, etc. that method should not be exposed through any autocompletion and that it should not appear through reflection. The only way that this method can be used is by already knowing if its existence, in which case the method can be used although obviously it will have to be typed out rather than autocompleted.
Simply knowing of the existence of the method indicates a suitable competency within the developer to make their usage of it relatively safe, thus satisfying the KISKIS principle.
Leave a Reply