目录

int hashCode()

描述 (Description)

java.math.MathContext.hashCode()返回此MathContext的哈希码。

声明 (Declaration)

以下是java.math.MathContext.hashCode()方法的声明。

public int hashCode()

覆盖 (Overrides)

Object类中的hashCode。

参数 (Parameters)

NA

返回值 (Return Value)

此方法返回此MathContext的哈希码。

异常 (Exception)

NA

例子 (Example)

以下示例显示了math.MathContext.hashCode()方法的用法。

package com.iowiki;
import java.math.*;
public class MathContextDemo {
   public static void main(String[] args) {
      // create 2 MathContext objects
      MathContext mc1, mc2;
      // assign context settings to mc1, mc2
      mc1 = new MathContext(5);
      mc2 = new MathContext(20, RoundingMode.UNNECESSARY);
      // create 2 int objects
      int i1, i2;
      // assign hashcode of mc1, mc2 to i1, i2
      i1 = mc1.hashCode();
      i2 = mc2.hashCode();
      String str1 = "Hashcode of mc1 is " + i1;
      String str2 = "Hashcode of mc2 is " + i2;
      // print i1, i2 values
      System.out.println( str1 );
      System.out.println( str2 );
   }
}

让我们编译并运行上面的程序,这将产生以下结果 -

Hashcode of mc1 is 1802290004
Hashcode of mc2 is -1299934805
↑回到顶部↑
WIKI教程 @2018