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.

  • 相关阅读:
    关于unittest框架的传参问题
    爬虫的框架:Scarpy
    Robot Frameworke在python3上搭建环境以及快捷方式的创建
    安装第三方模块报错:read time out
    操作正则表达式遇到的问题
    gil锁 线程队列 线程池
    并发编程
    网络编程传输文件
    粘包现象
    UDP协议下的socket
  • 原文地址:https://www.cnblogs.com/reynold-lei/p/3470411.html
Copyright © 2011-2022 走看看