Skip to content

Instantly share code, notes, and snippets.

@ucpwang
Created February 2, 2017 01:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ucpwang/e66fde2a43821355ab77b4914b82649e to your computer and use it in GitHub Desktop.
Save ucpwang/e66fde2a43821355ab77b4914b82649e to your computer and use it in GitHub Desktop.
[Q&A] javascript 'eval()' -> how can I do it in Java?
const cdtStr = '1 == 0';
function myFn() {
  let cdt = eval(conStr);
  console.log(`${cdtStr} ===> ${cdt}`);
  
  if (cdt) {
    console.log('in true');
  } else {
    console.log('in false');
  }
}
myFn();

위와 같이 javascript에서는 eval()을 통해 동적 컨디션을 활용할 수 있다.

(물론, 문제는 많을수 있으니 사전 벨리데이션 처리는 필요하겠다.)

그렇다면 java에서는 위와 같이 할 수 없을까?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment