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.

  • 相关阅读:
    BZOJ 3390 Bad Cowtractors牛的报复
    BZOJ 4291 Kieszonkowe
    【重温基础】3.循环和迭代
    【重温基础】3.循环和迭代
    【重温基础】2.流程控制和错误处理
    【重温基础】2.流程控制和错误处理
    【重温基础】1.语法和数据类型
    【重温基础】1.语法和数据类型
    vue axios全攻略
    vue axios全攻略
  • 原文地址:https://www.cnblogs.com/reynold-lei/p/3470411.html
Copyright © 2011-2022 走看看