问题列表 - 第43769页

Java:父类可以静态检索子类的类名吗?

在参考Java时,我想静态地知道当前类的类名.A是B的父类.我想在A(父类)中有一个静态String,它包含当前类的类名,但是当在B(子类)中引用这个静态String时,它应该包含B的班级名称.这可能吗?

例:

public class Parent {

protected static String MY_CLASS_NAME = ???
.
.
.
}

public class Child extends Parent {

public void testMethod() {
     if (MY_CLASS_NAME.equals(getClass().getName())) {
        System.out.println("We're equal!");
     }
}

}
Run Code Online (Sandbox Code Playgroud)

java inheritance static class classname

11
推荐指数
2
解决办法
6880
查看次数

为什么不总是自动调用toString()

那么为什么不总是调用toString?这是使用Android API的示例.

例如

@Override
public void onItemSelected(AdapterView<?> adapterView, View view,
        int position, long id) {
    Toast.makeText(this, adapterView, Toast.LENGTH_LONG).show();
}
Run Code Online (Sandbox Code Playgroud)

不会编译.但是,如果我将其更改为

@Override
public void onItemSelected(AdapterView<?> adapterView, View view,
            int position, long id) {
    Toast.makeText(this, adapterView.toString(), Toast.LENGTH_LONG).show();
}
Run Code Online (Sandbox Code Playgroud)

它会.实际差异是什么?

java android android-adapterview

2
推荐指数
3
解决办法
2475
查看次数

'lock(this)'是否适合同步每个成员函数?

我有一个Singleton高度依赖于XML它用作数据库的文件的类.在构造函数中,XML文件被读取,并且FileSystemWatcher正在监视任何进一步的更改.

现在,如果发生任何更改,我将XML再次从文件中读取数据,但此时应该可以访问非类函数,直到XML重新加载文件.

我的问题是我可以简单地this用作同步对象(在重新加载XML文件时)并且不对函数进行任何更改而不是lock对每个函数都进行大的改动吗?

c# locking this

1
推荐指数
2
解决办法
101
查看次数

我怎样才能摆脱图片框的边框?

我有PictureBox,我把它设置为BorderStyleNone但我仍然在它周围有一个边框。我怎样才能摆脱它?

还有什么细节?我的图像本身没有边框。我用代码

    private void btnLoad_Click(object sender, EventArgs e)
    {

        if (dgOpenFile.ShowDialog() == DialogResult.OK)
        {
            try
            {
                img = new Bitmap(dgOpenFile.FileName);

                picture.Size = img.Size;
                picture.Image = img;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
    }
Run Code Online (Sandbox Code Playgroud)

要打开并显示图像:

图像为 10x10。他们低于(800%)

原来的:

http://img695.imageshack.us/img695/2409/originallu.png

以及它的显示方式:

http://img209.imageshack.us/img209/7088/displayed.png

c# picturebox winforms

4
推荐指数
1
解决办法
9506
查看次数

Rails中包含默认的js

在创建新的Rails应用程序时,它会自动提供几个非常大的js文件.在应用程序布局中,默认情况下,所有这些都加载到页面中:

<%= javascript_include_tag :defaults %>
Run Code Online (Sandbox Code Playgroud)

我想知道,是不是加载所有那些javascripts可以使网站可能更慢?
如果是这样,我在哪里可以改变定义:defaults?或者我应该只包括我需要的那些并删除上面提到的代码行?

谢谢

html javascript ruby-on-rails

3
推荐指数
1
解决办法
3665
查看次数

C#:访问".NET CLR内存类别"的PerformanceCounters

我正在尝试使用PerformanceCounter类通过C#访问位于".NET CLR内存类别"中的性能计数器.但是,无法使用我期望的正确类别/计数器名称来实例化类别

new PerformanceCounter(".NET CLR Memory", "# bytes in all heaps", Process.GetCurrentProcess().ProcessName);
Run Code Online (Sandbox Code Playgroud)

我尝试使用以下代码循环遍历类别和计数器

string[] categories = PerformanceCounterCategory.GetCategories().Select(c => c.CategoryName).OrderBy(s => s).ToArray();
string toInspect = string.Join(",\r\n", categories);

System.Text.StringBuilder interestingToInspect = new System.Text.StringBuilder();
string[] interestingCategories = categories.Where(s => s.StartsWith(".NET") || s.Contains("Memory")).ToArray();
foreach (string interestingCategory in interestingCategories)
{
    PerformanceCounterCategory cat = new PerformanceCounterCategory(interestingCategory);
    foreach (PerformanceCounter counter in cat.GetCounters())
    {
        interestingToInspect.AppendLine(interestingCategory + ":" + counter.CounterName);
    }
}
toInspect = interestingToInspect.ToString();
Run Code Online (Sandbox Code Playgroud)

但找不到任何似乎匹配的东西.是不可能从CLR中观察这些值,或者我做错了什么.

重要的是,环境是在64位Windows 7机器上运行的.NET 4.0.

.net c# memory performancecounter

9
推荐指数
1
解决办法
5679
查看次数

显示模型状态错误

我有以下代码,但错误causght没有显示.怎么了 ?

  public ActionResult DeleteRateGroup(int id)
    {
        try
        {
           RateGroup.Load(id).Delete();

            RateGroupListModel list = new RateGroupListModel();
            return GetIndexView(list);
        }
        catch (Exception e)
        {
            RateGroupListModel model = new RateGroupListModel(); 

            if (e.InnerException != null)
            {
                if (e.InnerException.Message.Contains("REFERENCE constraint"))
                    ModelState.AddModelError("Error", "The user has related information and cannot be deleted.");
            }
            else
            {
                ModelState.AddModelError("Error", e.Message);
            }
            return RedirectToAction("RateGroup", model);
        }
    }
Run Code Online (Sandbox Code Playgroud)
    @model MvcUI.Models.RateGroupListModel

@{
    View.Title = "RateGroup";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<h2>Rate Group</h2>

@Html.ValidationSummary()

@using (Html.BeginForm())
Run Code Online (Sandbox Code Playgroud)
    private ActionResult GetIndexView(RateGroupListModel model)
    {
       return View("RateGroup", model);
    } …
Run Code Online (Sandbox Code Playgroud)

asp.net-mvc-3

9
推荐指数
1
解决办法
2万
查看次数

各种方法来阻止一个线程 - 这是正确的方法

我遇到了阻止线程的不同建议.我可以知道,这是正确的方法吗?还是取决于?

使用线程变量 http://download.oracle.com/javase/1.4.2/docs/guide/misc/threadPrimitiveDeprecation.html

private volatile Thread blinker;

public void stop() {
    blinker = null;
}

public void run() {
    Thread thisThread = Thread.currentThread();
    while (blinker == thisThread) {
        try {
            thisThread.sleep(interval);
        } catch (InterruptedException e){
        }
        repaint();
    }
}
Run Code Online (Sandbox Code Playgroud)

使用布尔标志

private volatile boolean flag;

public void stop() {
    flag = false;
}

public void run() {
    while (flag) {
        try {
            thisThread.sleep(interval);
        } catch (InterruptedException e){
        }
        repaint();
    }
}
Run Code Online (Sandbox Code Playgroud)

将线程变量与中断一起使用

private volatile Thread blinker;

public void stop() {
    blinker.interrupt(); …
Run Code Online (Sandbox Code Playgroud)

java multithreading

4
推荐指数
1
解决办法
2245
查看次数

http持久连接和ssl会话

HTTP是一种应用程序协议,可以关闭并重新打开底层TCP连接,而不会影响HTTP应用程序(性能除外).
通过使用HTTP1.1,我们使用持久连接,但服务器或客户端仍然可以随时关闭连接.
对于安全性,HTTP通过SSL/TLS使用TCP.
我的理解是SSL的行为很像应用程序,至少这是TCP"查看"SSL的方式.
我的问题是,如果底层TCP套接字在安全连接建立后的某个时刻关闭,这是否意味着SSL会话变得无效并且各方应该从ssl握手开始?
或者底层TCP连接与TLS会话无关?

谢谢!

ssl https tomcat http

7
推荐指数
1
解决办法
5734
查看次数

php数组foreach循环

我的购物篮是一个array,其中的每个项目也是一个array.

在某些时候,我循环遍历每个项目寻找ID匹配.当我有匹配时,我需要知道主basket数组中的Items位置,以便我可以执行更新和删除.

听起来很简单,但我坚持下去.

到目前为止我有这个

//Lets say there are 5 items in this basket array (each item is also an array)
foreach ($_SESSION['basket'] as $basketArray){

        //this loops through the items attributes (size, colour etc)
        //when the ID is a match, i need to find out what position I am at in the main     array
        foreach($basketArray at $key = > $value){

             if ($value == $itemID){

                   //now I just need to know how to return 0, 1, …
Run Code Online (Sandbox Code Playgroud)

php foreach loops return

2
推荐指数
1
解决办法
2万
查看次数