Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 15 additions & 16 deletions docs/java/basis/Java基础知识.md
Original file line number Diff line number Diff line change
Expand Up @@ -274,15 +274,15 @@ System.out.println(list);
```java
//此处T可以随便写为任意标识,常见的如T、E、K、V等形式的参数常用于表示泛型
//在实例化泛型类时,必须指定T的具体类型
public class Generic<T>{
public class Generic<T> {

private T key;

public Generic(T key) {
this.key = key;
}

public T getKey(){
public T getKey() {
return key;
}
}
Expand Down Expand Up @@ -316,7 +316,7 @@ class GeneratorImpl<T> implements Generator<T>{
实现泛型接口,指定类型:

```java
class GeneratorImpl<T> implements Generator<String>{
class GeneratorImpl implements Generator<String>{
@Override
public String method() {
return "hello";
Expand All @@ -327,13 +327,12 @@ class GeneratorImpl<T> implements Generator<String>{
**3.泛型方法** :

```java
public static < E > void printArray( E[] inputArray )
{
for ( E element : inputArray ){
System.out.printf( "%s ", element );
}
System.out.println();
public static <E> void printArray(E[] inputArray) {
for (E element : inputArray) {
System.out.printf("%s ", element);
}
System.out.println();
}
```

使用:
Expand All @@ -342,8 +341,8 @@ class GeneratorImpl<T> implements Generator<String>{
// 创建不同类型数组: Integer, Double 和 Character
Integer[] intArray = { 1, 2, 3 };
String[] stringArray = { "Hello", "World" };
printArray( intArray );
printArray( stringArray );
printArray(intArray);
printArray(stringArray);
```

**常用的通配符为: T,E,K,V,?**
Expand Down Expand Up @@ -457,7 +456,7 @@ public native int hashCode();

在这里解释一位小伙伴的问题。以下内容摘自《Head Fisrt Java》。

因为 `hashCode()` 所使用的杂凑算法也许刚好会让多个对象传回相同的杂凑值。越糟糕的杂凑算法越容易碰撞,但这也与数据值域分布的特性有关(所谓碰撞也就是指的是不同的对象得到相同的 `hashCode`。
因为 `hashCode()` 所使用的哈希算法也许刚好会让多个对象传回相同的哈希值。越糟糕的哈希算法越容易碰撞,但这也与数据值域分布的特性有关(所谓碰撞也就是指的是不同的对象得到相同的 `hashCode`。

我们刚刚也提到了 `HashSet`,如果 `HashSet` 在对比的时候,同样的 hashcode 有多个对象,它会使用 `equals()` 来判断是否真的相同。也就是说 `hashcode` 只是用来缩小查找成本。

Expand Down Expand Up @@ -750,7 +749,7 @@ public void f5(int a) {

首先,我们回顾一下在程序设计语言中有关将参数传递给方法(或函数)的一些专业术语。

**按值调用(call by value)** 表示方法接收的是调用者提供的值,**按引用调用(call by reference)** 表示方法接收的是调用者提供的变量地址。一个方法可以修改传递引用所对应的变量值,而不能修改传递值调用所对应的变量值。它用来描述各种程序设计语言(不只是 Java)中方法参数传递方式。
**按值调用(call by value)** 表示方法接收的是调用者提供的值,**按引用调用(call by reference)** 表示方法接收的是调用者提供的变量地址。一个方法可以修改传递引用所对应的变量值,而不能修改传递值调用所对应的变量值。它用来描述各种程序设计语言(不只是 Java中方法参数传递方式。

**Java 程序设计语言总是采用按值调用。也就是说,方法得到的是所有参数值的一个拷贝,也就是说,方法不能修改传递给它的任何参数变量的内容。**

Expand Down Expand Up @@ -1324,7 +1323,7 @@ try (BufferedInputStream bin = new BufferedInputStream(new FileInputStream(new F
}
```

## I\O 流
## I/O 流

### 什么是序列化?什么是反序列化?

Expand All @@ -1349,7 +1348,7 @@ try (BufferedInputStream bin = new BufferedInputStream(new FileInputStream(new F

### Java 序列化中如果有些字段不想进行序列化,怎么办?

`对于不想进行序列化的变量,使用`transient`关键字修饰。`
对于不想进行序列化的变量,使用`transient`关键字修饰。`

`transient` 关键字的作用是:阻止实例中那些用此关键字修饰的的变量序列化;当对象被反序列化时,被 `transient` 修饰的变量值不会被持久化和恢复。`transient` 只能修饰变量,不能修饰类和方法。

Expand Down Expand Up @@ -1399,4 +1398,4 @@ Java Io 流共涉及 40 多个类,这些类看上去很杂乱,但实际上

- https://stackoverflow.com/questions/1906445/what-is-the-difference-between-jdk-and-jre
- https://www.educba.com/oracle-vs-openjdk/
- https://stackoverflow.com/questions/22358071/differences-between-oracle-jdk-and-openjdk?answertab=active#tab-top## 基础概念与常识
- https://stackoverflow.com/questions/22358071/differences-between-oracle-jdk-and-openjdk 基础概念与常识