亚洲精品中文字幕无乱码_久久亚洲精品无码AV大片_最新国产免费Av网址_国产精品3级片

JAVA認(rèn)證

Java中靜態(tài)變量的適用場(chǎng)景

時(shí)間:2024-07-16 20:11:16 JAVA認(rèn)證 我要投稿
  • 相關(guān)推薦

Java中靜態(tài)變量的適用場(chǎng)景

  Java類中的靜態(tài)變量在程序運(yùn)行期間,其內(nèi)存空間對(duì)所有該類的對(duì)象實(shí)例而言是共享的,有些時(shí)候可以認(rèn)為是全局變量。因此在某些時(shí)候?yàn)榱斯?jié)省系統(tǒng)內(nèi)存開銷、共享資源,可以將類中的一些變量聲明為靜態(tài)變量,通過下面的例子,你可以發(fā)現(xiàn)合理應(yīng)用靜態(tài)變量帶來的好處:

  Java代碼

  public class WeekA{

  static class Data {

  private int week;

  private String name;

  Data(int i, String s) {

  week= i;

  name = s;

  }

  }

  Data weeks[] = {

  new Data(1, "Monday"), new Data(2, "Tuesay"), new Data(3, "Wednesday"), new Data(4, "Thursday"), new Data(5, "Friday"), new Data(6, "Saturday"), new Data(7, "Sunday")

  };

  public static void main(String args[]) {

  final int N = 10000;

  WeekA weekinstance;

  for (int i = 1; i <= N; i++){

  weekinstance = new WeekA ();

  }

  }

  }

  public class WeekA{

  static class Data {

  private int week;

  private String name;

  Data(int i, String s) {

  week= i;

  name = s;

  }

  }

  Data weeks[] = {

  new Data(1, "Monday"), new Data(2, "Tuesay"), new Data(3, "Wednesday"), new Data(4, "Thursday"), new Data(5, "Friday"), new Data(6, "Saturday"), new Data(7, "Sunday")

  };

  public static void main(String args[]) {

  final int N = 10000;

  WeekA weekinstance;

  for (int i = 1; i <= N; i++){

  weekinstance = new WeekA ();

  }

  }

  }

【Java中靜態(tài)變量的適用場(chǎng)景】相關(guān)文章:

php中static靜態(tài)變量的使用方法05-25

php靜態(tài)成員變量分享06-21

靜態(tài)化網(wǎng)站在SEO中的優(yōu)勢(shì)08-20

如何使用網(wǎng)絡(luò)中靜態(tài)IP地址10-02

CSS中關(guān)于變量的基本教程詳解07-12

在java中Synchronized的用法09-03

在Java中執(zhí)行JavaScript代碼07-03

Java中調(diào)用Oracle包的過程10-16

PHP的變量的介紹08-15

關(guān)于Java中Queue和BlockingQueue的區(qū)別08-28