小编Cod*_*nja的帖子

抛出UnsupportedOperationException

因此,方法描述之一如下:

public BasicLinkedList addToFront(T data)此操作对排序列表无效.将使用消息"排序列表的无效操作"生成UnsupportedOperationException.

我的代码是这样的:

public BasicLinkedList<T> addToFront(T data) {
    try {
        throw new UnsupportedOperationException("Invalid operation for sorted list.");
    } catch (java.lang.UnsupportedOperationException e) {
        System.out.println("Invalid operation for sorted list.");
    }
    return this;
}
Run Code Online (Sandbox Code Playgroud)

这是正确的做法吗?我只是打印出使用的消息,println()但是有不同的方式来生成消息吗?

java exception-handling try-catch

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

iOS11 UICollectionSectionHeader剪辑滚动指示器

我创建了一个单一的视图项目并添加了一个collectionView.我注册了一个UICollectionReusableView的简单子类

final class TestReusableView: UICollectionReusableView {
  override init(frame: CGRect) {
    super.init(frame: frame)
    backgroundColor = UIColor.red
  }
  ...
}
Run Code Online (Sandbox Code Playgroud)

将datasource和delegate设置为self

extension ViewController: UICollectionViewDataSource {
  func numberOfSections(in collectionView: UICollectionView) -> Int {
    return 1
  }

  func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
    return 100
  }

  func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView {
    let headerView = collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: kHeader, for: indexPath)
    return headerView
  }

  func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell …
Run Code Online (Sandbox Code Playgroud)

ios uicollectionview swift ios11

6
推荐指数
2
解决办法
741
查看次数

在OCaml中实现多个if语句

所以我对OCaml有点新意,我试图找出一种方法让我的函数检查多个条件并修改变量,如果这些条件中的任何一个为真

粗糙的伪代码会

var list = []
if cond1 then 1::list
if cond2 then 2::list
etc
Run Code Online (Sandbox Code Playgroud)

但是,一旦你输入if语句,我就可以告诉你,只要它返回一个值给函数,你就会保留它.有没有解决这个限制的方法?感谢您的时间,提示或提示非常感谢,因为我很想理解这门语言

recursion ocaml if-statement

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

Podfile麻烦

我安装了最新的cocoapods并在我的项目中运行了pod init.我用textedit手动打开文件,它看起来像这样:

# Uncomment this line to define a global platform for your project
platform :ios, ‘7.0’

pod ‘Wit’,  ‘~> 1.1.1’
Run Code Online (Sandbox Code Playgroud)

但是,当我运行pod安装时,我收到此错误

[!] Invalid `Podfile` file: /Users/me/projectfolder:4: syntax error, u
nexpected '~', expecting keyword_do or '{' or '('
pod ‘Wit’,  ‘~> 1.1.1’
                ^
/Users/me/projectfolder:4: no .<digit> floating literal anymore; put 0 before dot
pod ‘Wit’,  ‘~> 1.1.1’
                      ^. Updating CocoaPods might fix the issue.
Run Code Online (Sandbox Code Playgroud)

我错过了至关重要的事吗?我以为我非常密切地遵循安装说明,但也许我忘了一些东西.任何提示或提示将不胜感激.不熟悉cocoapods

macos ios cocoapods

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