小编kum*_*mar的帖子

如果我们只覆盖类中的hashCode()并在Set中使用它会发生什么?

这可能不是现实世界的场景,但只是想知道会发生什么,下面是代码.

我正在创建一组类的对象UsingSet.根据Java中的哈希概念,当我第一次添加包含"a"的对象时,它将创建一个带有哈希码97的桶并将对象放入其中.当它遇到带有"a"的对象时,它将在类UsingSet中调用重写的哈希码方法,它将获得哈希码97,那么下一步是什么?

由于我没有覆盖equals方法,因此默认实现将返回false.那么具有值"a"的Object将保留在哪个存储区中,其中保留了哈希码97的前一个对象?还是会创造新的桶?有谁知道它将如何存储在内部?

/* package whatever; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

class UsingSet {  

  String value;  

  public UsingSet(String value){  
    this.value = value;  
  }  

  public String toString() {  
    return value;  
  }  

  public int hashCode() {  
    int hash = value.hashCode();  
    System.out.println("hashcode called" + hash);  
    return hash;  
  }  

  public static void main(String args[]) {  

    java.util.Set s = new java.util.HashSet();  

    s.add(new UsingSet("A"));  
    s.add(new UsingSet("b"));  
    s.add(new UsingSet("a"));  
    s.add(new UsingSet("b"));   
    s.add(new UsingSet("a"));  

    s.add(new Integer(1));  
    s.add(new Integer(1));  

    System.out.println("s …
Run Code Online (Sandbox Code Playgroud)

java collections set

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

如何使用objective-c在UIWebView IOS中打开file.xlsx

我的IOS应用程序文档文件夹中有file.xlsx.我想在UIWebview中显示这个excel文件.但我得到低于错误,

Error Domain=WebKitErrorDomain Code=102 "Frame load interrupted" 
Run Code Online (Sandbox Code Playgroud)

但pdf和CSV文件正在打开,我是IOS的新手并尝试了所有可能的工作,我想从最近2天开始工作.什么都没有解决..请帮助我

更新:即使我将其重命名为file.xls,下面未打开的是我的代码,

    NSURL* nsUrl = [NSURL URLWithString:url];
        _urlReq = [NSURL URLWithString:url];
        [self performSelector:@selector(urlRequestForFile) withObject:nil afterDelay:0];
        _webView.delegate = self;
        NSURLRequest* request = [NSURLRequest requestWithURL: nsUrl];
        [_webView loadRequest: request];
Run Code Online (Sandbox Code Playgroud)
-(void)urlRequestForFile{
    self.connection = nil;
    NSURLRequest *requestForFile = [NSURLRequest requestWithURL:_urlReq cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:300];
    _connection = [[NSURLConnection alloc]initWithRequest:requestForFile delegate:self startImmediately:YES];
    _ongingServiceFlag = YES;

}
Run Code Online (Sandbox Code Playgroud)

需要帮助在我的IOS应用程序中使用UIWebView显示xlsx文件,还是有其他方法在应用程序内显示xlsx文件而不使用第三方应用程序?

更新(解决方案):
我很惊讶地看到即使在UIWebView的苹果网站中也没有提到XLSX的支持,但实际上UIWebView完全支持XLSX格式.您需要确保的一件事是指定正确的'textEncodingName'值.如果您的文件以base64二进制编码存储,则必须将其作为textEncodingName提及:@"base64"否则您必须提及"utf-8"

以下线为我工作:

[webView loadData:urlData MIMEType:@"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" textEncodingName:@"base64" baseURL:nil];
Run Code Online (Sandbox Code Playgroud)

objective-c uiwebview ios

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

java.util.logging 包在 Java 中不可访问

我正在尝试运行简单的 hello word java 程序并想要记录 hello world。但我收到错误

eclipse 中的声明为“无法访问包 java.util.logging” import java.util.logging.*;

我使用的是Java 11版本

完整代码如下

    package myproject;

    import java.io.Console;
    import java.io.File;
    import java.io.FileNotFoundException;
    import java.io.FileOutputStream;
    import java.io.IOException;
    import java.util.logging.Logger; 
    import java.util.logging.*;    

    public class FileOperations {

        public static void main(String[] args) {
            // Create a Logger 
            Logger logger = Logger.getLogger(FileOperations.class.getName());

            // Call info method 
            logger.info("This is message 1");
            // TODO Auto-generated method stub
            File file=new File("myFile.txt");
            FileOutputStream fos;

            try {
                fos = new FileOutputStream(file);
                fos.write(2);
                System.out.println("File operation completed");
                Logger.log(Level.INFO, "My …
Run Code Online (Sandbox Code Playgroud)

java eclipse

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

无法在Android应用程序中显示Mopub的原生广告

我已经与Mopub集成在我的Android应用程序中显示广告.我可以展示bannner和插页式广告,但不能展示原生广告,

布局文件代码,

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:orientation="vertical"  >
  <TextView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="@string/note_title_label"
    style="?android:listSeparatorTextViewStyle"
    />
  <EditText android:id="@+id/note_title"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:hint="@string/note_title_hint"
    />
    <TextView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="@string/note_details_label"
    style="?android:listSeparatorTextViewStyle"
    />
    <EditText android:id="@+id/note_details"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:hint="@string/note_details_hint"
    />
    <Button android:id="@+id/note_date"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginLeft="16dp"
    android:layout_marginRight="16dp"
    />
    <CheckBox android:id="@+id/note_solved"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginLeft="16dp"
    android:layout_marginRight="16dp"
    android:text="@string/note_solved_label"
    />

    <RelativeLayout  android:id="@+id/native_ad_layout"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="50dp">
    >    
    <ImageView android:id="@+id/native_ad_main_image"
                    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
        />  
    <ImageView android:id="@+id/native_ad_icon_image"
                    android:layout_width="fill_parent"
    android:layout_height="wrap_content"  
         />  
    <TextView android:id="@+id/native_ad_title" 
            android:layout_width="fill_parent"
    android:layout_height="wrap_content"
        />  
    <TextView android:id="@+id/native_ad_text" 
       android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        />
</RelativeLayout>

</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

fragment.java中的逻辑(与上面的布局相关联)用于显示原生广告的文件,

    @TargetApi(11) …
Run Code Online (Sandbox Code Playgroud)

android ads android-layout android-fragments mopub

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

无法找到用于获取我的Android应用的BSE股票报价的API

我在谷歌搜索了2天,但我仍然无法获得一个适当的API,我可以使用它来获取数据.我找到了一个API

https://finance.google.com/finance/info?client=w&q=BSE:YESBANK
Run Code Online (Sandbox Code Playgroud)

我正在获得共振数据,但数据不正确.我client=w在上面的URL中给出了错误

任何人都可以知道获取BSE数据的任何API吗?即使它是付费服务我也是...

stocks stockquotes google-finance-api stock

0
推荐指数
1
解决办法
6171
查看次数

npm uninstall 在 Mac 终端中不起作用

我已经使用安装了节点版本 14 npm install -g node@14。现在我尝试了以下命令来卸载节点版本 14,但它不起作用。

命令:

$ node -v
v14.19.0

$ npm unisntall node@14
npm WARN saveError ENOENT: no such file or directory, open '/Users/*****/package.json
npm WARN enoent ENOENT: no such file or directory, open '/Users/*****/package.json
npm WARN ***** No description
npm WARN ***** No repository field
npm WARN ***** No README data
npm WARN ***** No license field

up to date in 0.105s

$ node -v
v14.19.0

$ npm uninstall -g node
up to date in …
Run Code Online (Sandbox Code Playgroud)

node.js npm nvm npm-install

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