简体   繁体   English

J / Link中“if”语句的正确语法

[英]Proper syntax for “if” statement in J/Link

When writing in Java within Mathematica (using J/Link), do I use Java or Mathematica syntax for an If-Then statement? 在Mathematica中使用Java编写(使用J / Link)时,我是否将Java或Mathematica语法用于If-Then语句?

This question is not about any particular code. 这个问题与任何特定代码无关。 The answer should be the same, regardless of the code being used. 无论使用何种代码,答案都应该相同。 I know how to write using either syntax, I just don't know which one to use. 我知道如何使用任何一种语法编写,我只是不知道使用哪一种。

You can't really write java inside Mathematica. 你无法在Mathematica中真正编写java。 J/Link simply allows you to call Java functions via Mathematica and manipulate Mathematica objects-created based on Java objects. J / Link只允许您通过Mathematica调用Java函数并操作基于Java对象创建的Mathematica对象。 ( http://reference.wolfram.com/mathematica/JLink/tutorial/CallingJavaFromMathematica.html#15615 ) http://reference.wolfram.com/mathematica/JLink/tutorial/CallingJavaFromMathematica.html#15615

Hence you'll be writing if statements in Mathematica syntax. 因此,您将使用Mathematica语法编写if语句。 If[condition, t, f]

On a side note, the other side of J/Link allows you to use Mathematica from Java. 另外,J / Link的另一面允许您使用Java中的Mathematica。 Likewise you'll be writing java there in the majority of your code and calling something along the lines of ml.Evaluate("If[condition, t, f]") if you need to compute using Mathematica. 同样地ml.Evaluate("If[condition, t, f]")如果你需要使用Mathematica进行计算ml.Evaluate("If[condition, t, f]")你将在大多数代码中编写java并调用ml.Evaluate("If[condition, t, f]") For anyone interested, .NET/Link works the same. 对于任何感兴趣的人,.NET / Link都是一样的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM