我无法理解下面的代码如何打印50.0
public class Pre
{
public static void main(String[] args)
{
int x=10;
System.out.println((x > 10) ? 50.0 : 50); //output 50.0
}
}
Run Code Online (Sandbox Code Playgroud)
它应该打印50(我猜)不是50.0
上面的代码不等于下面的代码吗?
public class Pre
{
public static void main(String[] args)
{
int x=10;
if(x>10)
System.out.println(50.0);
else
System.out.println(50);//output
}
}
Run Code Online (Sandbox Code Playgroud)
如果它们是等价的,那么为什么输出的差异呢?
当我启动Spark shell时:
bin>./spark-shell
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
Spark assembly has been built with Hive, including Data nucleus jars on classpath
Welcome to SPARK VERSION 1.3.0
Using Scala version 2.10.4 (Java HotSpot(TM) Server VM, Java 1.7.0_75)
Type in expressions to have them evaluated.
Type :help for more information.
15/05/10 12:12:21 ERROR SparkDeploySchedulerBackend: Application has been killed. Reason: All masters are unresponsive! Giving up.
15/05/10 12:12:21 ERROR TaskSchedulerImpl: Exiting due to error from cluster scheduler: All masters are unresponsive! Giving up.
Run Code Online (Sandbox Code Playgroud)
我已经通过以下链接安装了spark:-http: //www.philchen.com/2015/02/16/how-to-install-apache-spark-and-cassandra-stack-on-ubuntu
问题1 - 为什么不将arrList1仅限于String?
ArrayList arrList1 = new ArrayList<String>();
arrList1.add(10);
arrList1.add("Manish");
arrList1.add(0.234);
Run Code Online (Sandbox Code Playgroud)
问题2 - 没有编译错误但是给出了运行类型错误的原因?
ArrayList<String> arrList2 = new ArrayList<String>();
arrList2 = arrList1;
Run Code Online (Sandbox Code Playgroud)
问题3 - 下面有什么用?
ArrayList<Integer> arrList3 = new ArrayList<Integer>();
arrList2 = arrList3; //compiler error that's fine
Run Code Online (Sandbox Code Playgroud)
问题4 - 如何在arrList4上进行操作?
ArrayList<?> arrList4 = new ArrayList<String>();
//arrList4.add("String"); //compilation error?
arrList4 = new ArrayList<Integer>();
arrList4.add(23); //compilation error?
Run Code Online (Sandbox Code Playgroud)
问题5 - 在分配对象时使用泛型是什么,因为它不起作用?在arrList1中?
ArrayList<String> arrList5 = new ArrayList();
arrList5.add("String");
arrList5.add(23.3); //compilation error that's fine
Run Code Online (Sandbox Code Playgroud)