zoukankan      html  css  js  c++  java
  • Chp14: Java

    1.finally keyword:

    finally keyword is used in association with a try/catch block and guarantees that a section of code will be executed, even if an exception is thrown. The finally block will be executed after the try and catch blocks, but before control transfers back to its origin.

    2. Overloading vs Overriding:

    overloading is a term used to describe when two methods have the same name but differ in the type or number of arguments.

    overriding is when a method shares the same name and function signature as another method in its super class.

    3. Java generics and C++ templates:

    C++ templates can use primitive types, like int. Java cannot and must instead use Integer.

    In Java, you can restrict the template's type parameters to be of a certain type. For instance, you might use generics to implement a CardDeck and specify that the type parameter must extend from CardGame.

    In C++, the type parameter can be instantiated, whereas Java does not support this.

    InJava, the type parameter cannot be used for static methods and variables, since these would be shared between MyClass<Foo> and MyClass<Bar>. In C++, these classes are different, so the type parameter can be used for static methods and variables.

    In Java, all instances of MyClass, regardless of their type parameters, are the same type. The type parameters are erased at runtime. In C++, instances with different type parameters are different types.

  • 相关阅读:
    BFS visit tree
    Kth Largest Element in an Array 解答
    Merge k Sorted Lists 解答
    Median of Two Sorted Arrays 解答
    Maximal Square 解答
    Best Time to Buy and Sell Stock III 解答
    Best Time to Buy and Sell Stock II 解答
    Best Time to Buy and Sell Stock 解答
    Triangle 解答
    Unique Binary Search Trees II 解答
  • 原文地址:https://www.cnblogs.com/reynold-lei/p/3470411.html
Copyright © 2011-2022 走看看